Debian Codegraph @

go/callgraph/vta/testdata/src/callgraph_pointers.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 f *I
15 }
16
17 func (a A) Foo() {}
18
19 type B struct{}
20
21 func (b B) Foo() {}
22
23 func Do(a A, i I, c bool) *I {
24 if c {
25 *a.f = a
26 } else {
27 a.f = &i
28 }
29 (*a.f).Foo()
30 return &i
31 }
32
33 func Baz(a A, b B, c bool) {
34 x := Do(a, b, c)
35 (*x).Foo()
36 }
37
38 // The command a.f = &i introduces aliasing that results in
39 // A and B reaching both *A.f and return value of Do(a, b, c).
40
41 // WANT:
42 // Baz: Do(a, t0, c) -> Do; invoke t2.Foo() -> A.Foo, B.Foo
43 // Do: invoke t8.Foo() -> A.Foo, B.Foo