golang.org/x/tools@v0.21.1-0.20240520172518-788d39e776b1/go/callgraph/vta/testdata/src/callgraph_collections.go (about)

     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  func Do(a A, b B) map[I]I {
    22  	m := make(map[I]I)
    23  	m[a] = B{}
    24  	m[b] = b
    25  	return m
    26  }
    27  
    28  func Baz(a A, b B) {
    29  	var x []I
    30  	for k, v := range Do(a, b) {
    31  		k.Foo()
    32  		v.Foo()
    33  
    34  		x = append(x, k)
    35  	}
    36  
    37  	x[len(x)-1].Foo()
    38  }
    39  
    40  // WANT:
    41  // Baz: Do(a, b) -> Do; invoke t16.Foo() -> A.Foo, B.Foo; invoke t5.Foo() -> A.Foo, B.Foo; invoke t6.Foo() -> B.Foo