modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue9017.go (about) 1 // errorcheck 2 3 // Copyright 2014 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 // Issue 9017: Method selector shouldn't automatically dereference a named pointer type. 8 9 package main 10 11 type T struct{ x int } 12 13 func (T) mT() {} 14 15 type S struct { 16 T 17 } 18 19 func (S) mS() {} 20 21 type P *S 22 23 type I interface { 24 mT() 25 } 26 27 func main() { 28 var s S 29 s.T.mT() 30 s.mT() // == s.T.mT() 31 32 var i I 33 _ = i 34 i = s.T 35 i = s 36 37 var ps = &s 38 ps.mS() 39 ps.T.mT() 40 ps.mT() // == ps.T.mT() 41 42 i = ps.T 43 i = ps 44 45 var p P = ps 46 (*p).mS() 47 p.mS() // ERROR "undefined" 48 49 i = *p 50 i = p // ERROR "cannot use|incompatible types" 51 52 p.T.mT() 53 p.mT() // ERROR "undefined" 54 55 i = p.T 56 i = p // ERROR "cannot use|incompatible types" 57 }