-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/callgraph/rta: adds tests for (instantiated) generics
Updates golang/go#48525 Change-Id: I7e25ab136dd69ebd50b12894bc893986fc59999b Reviewed-on: https://go-review.googlesource.com/c/tools/+/402994 Run-TryBot: Zvonimir Pavlinovic <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Tim King <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
- Loading branch information
1 parent
ed968f6
commit 29d48d6
Showing
3 changed files
with
148 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//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() | ||
} | ||
|
||
var a A | ||
var b B | ||
|
||
func main() { | ||
instantiated[A](a) // static call | ||
instantiated[B](b) // static call | ||
|
||
local[C]().Foo() | ||
|
||
lambda[A]()()() | ||
} | ||
|
||
func local[X I]() I { | ||
var x X | ||
return x | ||
} | ||
|
||
type C struct{} | ||
|
||
func (c C) Foo() {} | ||
|
||
func lambda[X I]() func() func() { | ||
return func() func() { | ||
var x X | ||
return x.Foo | ||
} | ||
} | ||
|
||
// WANT: | ||
// All calls | ||
// (*C).Foo --> (C).Foo | ||
// (A).Foo$bound --> (A).Foo | ||
// instantiated[[main.A]] --> (A).Foo | ||
// instantiated[[main.B]] --> (B).Foo | ||
// main --> (*C).Foo | ||
// main --> (A).Foo$bound | ||
// main --> (C).Foo | ||
// main --> instantiated[[main.A]] | ||
// main --> instantiated[[main.B]] | ||
// main --> lambda[[main.A]] | ||
// main --> lambda[[main.A]]$1 | ||
// main --> local[[main.C]] | ||
// Reachable functions | ||
// (*C).Foo | ||
// (A).Foo | ||
// (A).Foo$bound | ||
// (B).Foo | ||
// (C).Foo | ||
// instantiated[[main.A]] | ||
// instantiated[[main.B]] | ||
// lambda[[main.A]] | ||
// lambda[[main.A]]$1 | ||
// local[[main.C]] | ||
// Reflect types | ||
// *C | ||
// C |