GoPLS Viewer

Home|gopls/go/callgraph/vta/testdata/src/dynamic_calls.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(I)
11}
12
13type A struct{}
14
15func (a Afoo(ai I) {}
16
17type B struct{}
18
19func (b Bfoo(bi I) {}
20
21func doWork() I { return nil }
22func close() I  { return nil }
23
24func Baz(x Bh func() Ii II {
25    i.foo(x)
26
27    return h()
28}
29
30// Relevant SSA:
31// func Baz(x B, h func() I, i I) I:
32//   t0 = local B (x)
33//   *t0 = x
34//   t1 = *t0
35//   t2 = make I <- B (t1)
36//   t3 = invoke i.foo(t2)
37//   t4 = h()
38//   return t4
39
40// Local(t2) has seemingly duplicates of successors. This
41// happens in stringification of type propagation graph.
42// Due to CHA, we analyze A.foo and *A.foo as well as B.foo
43// and *B.foo, which have similar bodies and hence similar
44// type flow that gets merged together during stringification.
45
46// WANT:
47// Local(t2) -> Local(ai), Local(ai), Local(bi), Local(bi)
48// Constant(testdata.I) -> Local(t4)
49// Local(t1) -> Local(t2)
50
MembersX
close
A.foo.ai
B.foo.b
B.foo
B.foo.bi
doWork
Members
X