Debian Codegraph @

go/callgraph/vta/testdata/src/callgraph_interfaces.go

raw symbols SCIP
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
7 package testdata
8
9 type I interface {
10 Foo()
11 }
12
13 type A struct{}
14
15 func (a A) Foo() {}
16
17 type B struct{}
18
19 func (b B) Foo() {}
20
21 type C struct{}
22
23 func (c C) Foo() {}
24
25 func NewB() B {
26 return B{}
27 }
28
29 func Do(b bool) I {
30 if b {
31 return A{}
32 }
33
34 c := C{}
35 c.Foo()
36
37 return NewB()
38 }
39
40 func 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 // t1 = (C).Foo(C{}:C)
53 // t2 = NewB()
54 // t3 = make I <- B (t2)
55 // return t3
56
57 // WANT:
58 // Baz: Do(b) -> Do; invoke t0.Foo() -> A.Foo, B.Foo
59 // Do: (C).Foo(C{}:C) -> C.Foo; NewB() -> NewB