3 // Copyright 2016 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Test basic restrictions on type aliases.
18 // Valid type alias declarations.
23 type _ = reflect.Value
37 // Methods can be declared on the original named type and the alias.
38 func (T0) m1() {} // GCCGO_ERROR "previous"
39 func (*T0) m1() {} // ERROR "method redeclared: T0\.m1|T0\.m1 redeclared in this block|redefinition of .m1."
40 func (A0) m1() {} // ERROR "T0\.m1 redeclared in this block|redefinition of .m1."
41 func (A0) m1() {} // ERROR "T0\.m1 redeclared in this block|redefinition of .m1."
44 // Type aliases and the original type name can be used interchangeably.
48 // But aliases and original types cannot be used with new types based on them.
49 var _ N0 = T0{} // ERROR "cannot use T0{} \(type T0\) as type N0 in assignment|incompatible type"
50 var _ N0 = A0{} // ERROR "cannot use T0{} \(type T0\) as type N0 in assignment|incompatible type"
68 type _ = reflect.Value
85 var _ N0 = T0{} // ERROR "cannot use T0{} \(type T0\) as type N0 in assignment|incompatible type"
86 var _ N0 = A0{} // ERROR "cannot use T0{} \(type T0\) as type N0 in assignment|incompatible type"
88 var _ A5 = Value{} // ERROR "cannot use reflect\.Value{} \(type reflect.Value\) as type A5 in assignment|incompatible type"
91 // Invalid type alias declarations.
93 type _ = reflect.ValueOf // ERROR "reflect.ValueOf .*is not a type|expected type"
95 func (A1) m() {} // ERROR "cannot define new methods on non-local type int|may not define methods on non-local type"
96 func (A2) m() {} // ERROR "invalid receiver type"
97 func (A3) m() {} // ERROR "cannot define new methods on non-local type reflect.Value|may not define methods on non-local type"
98 func (A4) m() {} // ERROR "cannot define new methods on non-local type reflect.Value|may not define methods on non-local type"
102 func (B1) m() {} // ERROR "invalid receiver type"