github.com/aloncn/graphics-go@v0.0.1/src/go/types/testdata/decls2a.src (about) 1 // Copyright 2012 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // method declarations 6 7 package decls2 8 9 import "time" 10 import "unsafe" 11 12 // T1 declared before its methods. 13 type T1 struct{ 14 f int 15 } 16 17 func (T1) m() {} 18 func (T1) m /* ERROR "already declared" */ () {} 19 func (x *T1) f /* ERROR "field and method" */ () {} 20 21 // Conflict between embedded field and method name, 22 // with the embedded field being a basic type. 23 type T1b struct { 24 int 25 } 26 27 func (T1b) int /* ERROR "field and method" */ () {} 28 29 type T1c struct { 30 time.Time 31 } 32 33 func (T1c) Time /* ERROR "field and method" */ () int { return 0 } 34 35 // Disabled for now: LookupFieldOrMethod will find Pointer even though 36 // it's double-declared (it would cost extra in the common case to verify 37 // this). But the MethodSet computation will not find it due to the name 38 // collision caused by the double-declaration, leading to an internal 39 // inconsistency while we are verifying one computation against the other. 40 // var _ = T1c{}.Pointer 41 42 // T2's method declared before the type. 43 func (*T2) f /* ERROR "field and method" */ () {} 44 45 type T2 struct { 46 f int 47 } 48 49 // Methods declared without a declared type. 50 func (undeclared /* ERROR "undeclared" */) m() {} 51 func (x *undeclared /* ERROR "undeclared" */) m() {} 52 53 func (pi /* ERROR "not a type" */) m1() {} 54 func (x pi /* ERROR "not a type" */) m2() {} 55 func (x *pi /* ERROR "not a type" */ ) m3() {} 56 57 // Blank types. 58 type _ struct { m int } 59 type _ struct { m int } 60 61 func (_ /* ERROR "cannot use _" */) m() {} 62 func m(_ /* ERROR "cannot use _" */) {} 63 64 // Methods with receiver base type declared in another file. 65 func (T3) m1() {} 66 func (*T3) m2() {} 67 func (x T3) m3() {} 68 func (x *T3) f /* ERROR "field and method" */ () {} 69 70 // Methods of non-struct type. 71 type T4 func() 72 73 func (self T4) m() func() { return self } 74 75 // Methods associated with an interface. 76 type T5 interface { 77 m() int 78 } 79 80 func (T5 /* ERROR "invalid receiver" */ ) m1() {} 81 func (T5 /* ERROR "invalid receiver" */ ) m2() {} 82 83 // Methods associated with a named pointer type. 84 type ptr *int 85 func (ptr /* ERROR "invalid receiver" */ ) _() {} 86 func (* /* ERROR "invalid receiver" */ ptr) _() {} 87 88 // Methods with zero or multiple receivers. 89 func ( /* ERROR "missing receiver" */ ) _() {} 90 func (T3, * /* ERROR "exactly one receiver" */ T3) _() {} 91 func (T3, T3, T3 /* ERROR "exactly one receiver" */ ) _() {} 92 func (a, b /* ERROR "exactly one receiver" */ T3) _() {} 93 func (a, b, c /* ERROR "exactly one receiver" */ T3) _() {} 94 95 // Methods associated with non-local or unnamed types. 96 func (int /* ERROR "invalid receiver" */ ) m() {} 97 func ([ /* ERROR "invalid receiver" */ ]int) m() {} 98 func (time /* ERROR "invalid receiver" */ .Time) m() {} 99 func (* /* ERROR "invalid receiver" */ time.Time) m() {} 100 func (x /* ERROR "invalid receiver" */ interface{}) m() {} 101 102 // Unsafe.Pointer is treated like a pointer when used as receiver type. 103 type UP unsafe.Pointer 104 func (UP /* ERROR "invalid" */ ) m1() {} 105 func (* /* ERROR "invalid" */ UP) m2() {} 106 107 // Double declarations across package files 108 const c_double = 0 109 type t_double int 110 var v_double int 111 func f_double() {}