GoPLS Viewer

Home|gopls/go/callgraph/vta/testdata/src/fields.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 J interface {
14    I
15    Bar()
16}
17
18type A struct{}
19
20func (a AFoo() {}
21func (a ABar() {}
22
23type B struct {
24    a A
25    i I
26}
27
28func Do() B {
29    b := B{}
30    return b
31}
32
33func Baz(b B) {
34    var j J
35    j = b.a
36
37    j.Bar()
38
39    b.i = j
40
41    Do().i.Foo()
42}
43
44// Relevant SSA:
45// func Baz(b B):
46//   t0 = local B (b)
47//   *t0 = b
48//   t1 = &t0.a [#0]       // no flow here since a is of concrete type
49//   t2 = *t1
50//   t3 = make J <- A (t2)
51//   t4 = invoke t3.Bar()
52//   t5 = &t0.i [#1]
53//   t6 = change interface I <- J (t3)
54//   *t5 = t6
55//   t7 = Do()
56//   t8 = t7.i [#0]
57//   t9 = (A).Foo(t8)
58//   return
59
60// WANT:
61// Field(testdata.B:i) -> Local(t5), Local(t8)
62// Local(t5) -> Field(testdata.B:i)
63// Local(t2) -> Local(t3)
64// Local(t3) -> Local(t6)
65// Local(t6) -> Local(t5)
66
MembersX
Baz.BlockStmt.j
J
A.Bar.a
A.Bar
B.a
B.i
Do.BlockStmt.b
Members
X