GoPLS Viewer

Home|gopls/go/callgraph/rta/testdata/iface.go
1// +build ignore
2
3package main
4
5// Test of interface calls.
6
7func use(interface{})
8
9type A byte // instantiated but not a reflect type
10
11func (Af() {} // called directly
12func (AF() {} // unreachable
13
14type B int // a reflect type
15
16func (*Bf() {} // reachable via interface invoke
17func (*BF() {} // reachable: exported method of reflect type
18
19type B2 int // a reflect type, and *B2 also
20
21func (B2f() {} // reachable via interface invoke
22func (B2g() {} // reachable: exported method of reflect type
23
24type C string // not instantiated
25
26func (Cf() {} // unreachable
27func (CF() {} // unreachable
28
29type D uint // instantiated only in dead code
30
31func (Df() {} // unreachable
32func (DF() {} // unreachable
33
34func 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
48func 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
56func 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
80
MembersX
B.F
B2
D.f
use
A.f
C
D.F
B.f
B2.g
C.f
C.F
dead
A
A.F
B2.f
D
live
Members
X