GoPLS Viewer

Home|gopls/go/callgraph/vta/testdata/src/callgraph_interfaces.go
1// Copyright 2021 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// go:build ignore
6
7package testdata
8
9type I interface {
10    Foo()
11}
12
13type A struct{}
14
15func (a AFoo() {}
16
17type B struct{}
18
19func (b BFoo() {}
20
21type C struct{}
22
23func (c CFoo() {}
24
25func NewB() B {
26    return B{}
27}
28
29func Do(b boolI {
30    if b {
31        return A{}
32    }
33
34    c := C{}
35    c.Foo()
36
37    return NewB()
38}
39
40func Baz(b bool) {
41    Do(b).Foo()
42}
43
44// Relevant SSA:
45// func Baz(b bool):
46//   t0 = Do(b)
47//   t1 = invoke t0.Foo()
48//   return
49
50// func Do(b bool) I:
51//    ...
52//   t3 = local C (c)
53//   t4 = *t3
54//   t5 = (C).Foo(t4)
55//   t6 = NewB()
56//   t7 = make I <- B (t6)
57//   return t7
58
59// WANT:
60// Baz: Do(b) -> Do; invoke t0.Foo() -> A.Foo, B.Foo
61// Do: (C).Foo(t4) -> C.Foo; NewB() -> NewB
62
MembersX
C
C.Foo.c
C.Foo
NewB
Do.BlockStmt.c
Members
X