GoPLS Viewer

Home|gopls/go/callgraph/cha/testdata/iface.go
1// +build ignore
2
3package main
4
5// Test of interface calls.  None of the concrete types are ever
6// instantiated or converted to interfaces.
7
8type I interface {
9    f()
10}
11
12type J interface {
13    f()
14    g()
15}
16
17type C int // implements I
18
19func (*Cf()
20
21type D int // implements I and J
22
23func (*Df()
24func (*Dg()
25
26func one(i Ij J) {
27    i.f() // calls *C and *D
28}
29
30func two(i Ij J) {
31    j.f() // calls *D (but not *C, even though it defines method f)
32}
33
34func three(i Ij J) {
35    j.g() // calls *D
36}
37
38func four(i Ij J) {
39    Jf := J.f
40    if unknown {
41        Jf = nil // suppress SSA constant propagation
42    }
43    Jf(nil// calls *D
44}
45
46func five(i Ij J) {
47    jf := j.f
48    if unknown {
49        jf = nil // suppress SSA constant propagation
50    }
51    jf() // calls *D
52}
53
54var unknown bool
55
56// WANT:
57// Dynamic calls
58//   (J).f$bound --> (*D).f
59//   (J).f$thunk --> (*D).f
60//   five --> (J).f$bound
61//   four --> (J).f$thunk
62//   one --> (*C).f
63//   one --> (*D).f
64//   three --> (*D).g
65//   two --> (*D).f
66
MembersX
one.i
four.i
unknown
D
C.f
D.f
four.j
four.Jf
five.j
I
one
one.j
two
two.i
three.i
three.j
five
J
five.jf
D.g
two.j
three
four
five.i
C
Members
X