1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
//go:build ignore
// +build ignore
package main
// Test of generic function calls.
type I interface {
Foo()
}
type A struct{}
func (a A) Foo() {}
type B struct{}
func (b B) Foo() {}
func instantiated[X I](x X) {
x.Foo()
}
func Bar() {}
func f(h func(), g func(I), k func(A), a A, b B) {
h()
k(a)
g(b) // g:func(I) is not matched by instantiated[B]:func(B)
instantiated[A](a) // static call
instantiated[B](b) // static call
}
// WANT:
// All calls
// (*A).Foo --> (A).Foo
// (*B).Foo --> (B).Foo
// f --> Bar
// f --> instantiated[main.A]
// f --> instantiated[main.A]
// f --> instantiated[main.B]
// instantiated --> (*A).Foo
// instantiated --> (*B).Foo
// instantiated --> (A).Foo
// instantiated --> (B).Foo
// instantiated[main.A] --> (A).Foo
// instantiated[main.B] --> (B).Foo
|