github.com/zach-klippenstein/go@v0.0.0-20150108044943-fcfbeb3adf58/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 "method" 37 var _ = pv.val // ERROR "method"