| 1 |
-- go.mod -- |
| 2 |
module example.com |
| 3 |
go 1.18 |
| 4 |
|
| 5 |
-- iface.go -- |
| 6 |
package main |
| 7 |
|
| 8 |
import ( |
| 9 |
"example.com/subpkg" |
| 10 |
) |
| 11 |
|
| 12 |
func use(interface{}) |
| 13 |
|
| 14 |
// Test of interface calls. |
| 15 |
|
| 16 |
func main() { |
| 17 |
use(subpkg.A(0)) |
| 18 |
use(new(subpkg.B)) |
| 19 |
use(subpkg.B2(0)) |
| 20 |
|
| 21 |
var i interface { |
| 22 |
F() |
| 23 |
} |
| 24 |
|
| 25 |
// assign an interface type with a function return interface value |
| 26 |
i = subpkg.NewInterfaceF() |
| 27 |
|
| 28 |
i.F() |
| 29 |
} |
| 30 |
|
| 31 |
func dead() { |
| 32 |
use(subpkg.D(0)) |
| 33 |
} |
| 34 |
|
| 35 |
// WANT: |
| 36 |
// |
| 37 |
// edge (*example.com/subpkg.A).F --static method call--> (example.com/subpkg.A).F |
| 38 |
// edge (*example.com/subpkg.B2).F --static method call--> (example.com/subpkg.B2).F |
| 39 |
// edge (*example.com/subpkg.C).F --static method call--> (example.com/subpkg.C).F |
| 40 |
// edge init --static function call--> example.com/subpkg.init |
| 41 |
// edge main --dynamic method call--> (*example.com/subpkg.A).F |
| 42 |
// edge main --dynamic method call--> (*example.com/subpkg.B).F |
| 43 |
// edge main --dynamic method call--> (*example.com/subpkg.B2).F |
| 44 |
// edge main --dynamic method call--> (*example.com/subpkg.C).F |
| 45 |
// edge main --dynamic method call--> (example.com/subpkg.A).F |
| 46 |
// edge main --dynamic method call--> (example.com/subpkg.B2).F |
| 47 |
// edge main --dynamic method call--> (example.com/subpkg.C).F |
| 48 |
// edge main --static function call--> example.com/subpkg.NewInterfaceF |
| 49 |
// edge main --static function call--> use |
| 50 |
// |
| 51 |
// reachable (*example.com/subpkg.A).F |
| 52 |
// reachable (*example.com/subpkg.B).F |
| 53 |
// reachable (*example.com/subpkg.B2).F |
| 54 |
// reachable (*example.com/subpkg.C).F |
| 55 |
// reachable (example.com/subpkg.A).F |
| 56 |
// !reachable (example.com/subpkg.B).F |
| 57 |
// reachable (example.com/subpkg.B2).F |
| 58 |
// reachable (example.com/subpkg.C).F |
| 59 |
// reachable example.com/subpkg.NewInterfaceF |
| 60 |
// reachable example.com/subpkg.init |
| 61 |
// !reachable (*example.com/subpkg.D).F |
| 62 |
// !reachable (example.com/subpkg.D).F |
| 63 |
// reachable init |
| 64 |
// reachable main |
| 65 |
// reachable use |
| 66 |
// |
| 67 |
// rtype *example.com/subpkg.A |
| 68 |
// rtype *example.com/subpkg.B |
| 69 |
// rtype *example.com/subpkg.B2 |
| 70 |
// rtype *example.com/subpkg.C |
| 71 |
// rtype example.com/subpkg.B |
| 72 |
// rtype example.com/subpkg.A |
| 73 |
// rtype example.com/subpkg.B2 |
| 74 |
// rtype example.com/subpkg.C |
| 75 |
// !rtype example.com/subpkg.D |
| 76 |
|
| 77 |
-- subpkg/impl.go -- |
| 78 |
package subpkg |
| 79 |
|
| 80 |
type InterfaceF interface { |
| 81 |
F() |
| 82 |
} |
| 83 |
|
| 84 |
type A byte // instantiated but not a reflect type |
| 85 |
|
| 86 |
func (A) F() {} // reachable: exported method of reflect type |
| 87 |
|
| 88 |
type B int // a reflect type |
| 89 |
|
| 90 |
func (*B) F() {} // reachable: exported method of reflect type |
| 91 |
|
| 92 |
type B2 int // a reflect type, and *B2 also |
| 93 |
|
| 94 |
func (B2) F() {} // reachable: exported method of reflect type |
| 95 |
|
| 96 |
type C string |
| 97 |
|
| 98 |
func (C) F() {} // reachable: exported by NewInterfaceF |
| 99 |
|
| 100 |
func NewInterfaceF() InterfaceF { |
| 101 |
return C("") |
| 102 |
} |
| 103 |
|
| 104 |
type D uint // instantiated only in dead code |
| 105 |
|
| 106 |
func (*D) F() {} // unreachable |