Debian Codegraph @

go/callgraph/vta/testdata/src/callgraph_issue_57756.go

raw symbols SCIP
1 // Copyright 2023 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 // Test that the values of a named function type are correctly
10 // flowing from interface objects i in i.Foo() to the receiver
11 // parameters of callees of i.Foo().
12
13 type H func()
14
15 func (h H) Do() {
16 h()
17 }
18
19 type I interface {
20 Do()
21 }
22
23 func Bar() I {
24 return H(func() {})
25 }
26
27 func For(g G) {
28 b := Bar()
29 b.Do()
30
31 g[0] = b
32 g.Goo()
33 }
34
35 type G []I
36
37 func (g G) Goo() {
38 g[0].Do()
39 }
40
41 // Relevant SSA:
42 // func Bar$1():
43 // return
44 //
45 // func Bar() I:
46 // t0 = changetype H <- func() (Bar$1)
47 // t1 = make I <- H (t0)
48 //
49 // func For():
50 // t0 = Bar()
51 // t1 = invoke t0.Do()
52 // t2 = &g[0:int]
53 // *t2 = t0
54 // t3 = (G).Goo(g)
55 //
56 // func (h H) Do():
57 // t0 = h()
58 //
59 // func (g G) Goo():
60 // t0 = &g[0:int]
61 // t1 = *t0
62 // t2 = invoke t1.Do()
63
64 // WANT:
65 // For: (G).Goo(g) -> G.Goo; Bar() -> Bar; invoke t0.Do() -> H.Do
66 // H.Do: h() -> Bar$1
67 // G.Goo: invoke t1.Do() -> H.Do