github.com/golangci/go-tools@v0.0.0-20190318060251-af6baa5dc196/callgraph/rta/testdata/iface.go (about) 1 //+build ignore 2 3 package main 4 5 // Test of interface calls. 6 7 func use(interface{}) 8 9 type A byte // instantiated but not a reflect type 10 11 func (A) f() {} // called directly 12 func (A) F() {} // unreachable 13 14 type B int // a reflect type 15 16 func (*B) f() {} // reachable via interface invoke 17 func (*B) F() {} // reachable: exported method of reflect type 18 19 type B2 int // a reflect type, and *B2 also 20 21 func (B2) f() {} // reachable via interface invoke 22 func (B2) g() {} // reachable: exported method of reflect type 23 24 type C string // not instantiated 25 26 func (C) f() {} // unreachable 27 func (C) F() {} // unreachable 28 29 type D uint // instantiated only in dead code 30 31 func (D) f() {} // unreachable 32 func (D) F() {} // unreachable 33 34 func main() { 35 A(0).f() 36 37 use(new(B)) 38 use(B2(0)) 39 40 var i interface { 41 f() 42 } 43 i.f() // calls (*B).f, (*B2).f and (B2.f) 44 45 live() 46 } 47 48 func live() { 49 var j interface { 50 f() 51 g() 52 } 53 j.f() // calls (B2).f and (*B2).f but not (*B).f (no g method). 54 } 55 56 func dead() { 57 use(D(0)) 58 } 59 60 // WANT: 61 // Dynamic calls 62 // live --> (*B2).f 63 // live --> (B2).f 64 // main --> (*B).f 65 // main --> (*B2).f 66 // main --> (B2).f 67 // Reachable functions 68 // (*B).F 69 // (*B).f 70 // (*B2).f 71 // (A).f 72 // (B2).f 73 // live 74 // use 75 // Reflect types 76 // *B 77 // *B2 78 // B 79 // B2