modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/method2.go (about) 1 // errorcheck 2 3 // Copyright 2009 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. 6 7 // Verify that pointers and interface types cannot be method receivers. 8 // Does not compile. 9 10 package main 11 12 type T struct { 13 a int 14 } 15 type P *T 16 type P1 *T 17 18 func (p P) val() int { return 1 } // ERROR "receiver.* pointer|invalid pointer or interface receiver" 19 func (p *P1) val() int { return 1 } // ERROR "receiver.* pointer|invalid pointer or interface receiver" 20 21 type I interface{} 22 type I1 interface{} 23 24 func (p I) val() int { return 1 } // ERROR "receiver.*interface|invalid pointer or interface receiver" 25 func (p *I1) val() int { return 1 } // ERROR "receiver.*interface|invalid pointer or interface receiver" 26 27 type Val interface { 28 val() int 29 } 30 31 var _ = (*Val).val // ERROR "method" 32 33 var v Val 34 var pv = &v 35 36 var _ = pv.val() // ERROR "pv.val undefined" 37 var _ = pv.val // ERROR "pv.val undefined" 38 39 func (t *T) g() int { return t.a } 40 41 var _ = (T).g() // ERROR "needs pointer receiver|undefined"