Skip to content

Commit 23e1af6

Browse files
xieyuschengopherbot
authored andcommitted
go/ssa: migrate TestGenericFunctionSelector away from loader
Use qualified identifier to check instantiated function. Updates golang/go#69556 Change-Id: I857de1b3d13d052dc09d96454715f8128237362e Reviewed-on: https://go-review.googlesource.com/c/tools/+/614995 Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Tim King <[email protected]>
1 parent 8adb6e8 commit 23e1af6

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

go/ssa/builder_test.go

+15-18
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"golang.org/x/sync/errgroup"
2626
"golang.org/x/tools/go/analysis/analysistest"
27-
"golang.org/x/tools/go/buildutil"
2827
"golang.org/x/tools/go/expect"
2928
"golang.org/x/tools/go/loader"
3029
"golang.org/x/tools/go/packages"
@@ -767,30 +766,28 @@ func sliceMax(s []int) []int { return s[a():b():c()] }
767766

768767
// TestGenericFunctionSelector ensures generic functions from other packages can be selected.
769768
func TestGenericFunctionSelector(t *testing.T) {
770-
pkgs := map[string]map[string]string{
771-
"main": {"m.go": `package main; import "a"; func main() { a.F[int](); a.G[int,string](); a.H(0) }`},
772-
"a": {"a.go": `package a; func F[T any](){}; func G[S, T any](){}; func H[T any](a T){} `},
773-
}
769+
fsys := overlayFS(map[string][]byte{
770+
"go.mod": goMod("example.com", -1),
771+
"main.go": []byte(`package main; import "example.com/a"; func main() { a.F[int](); a.G[int,string](); a.H(0) }`),
772+
"a/a.go": []byte(`package a; func F[T any](){}; func G[S, T any](){}; func H[T any](a T){} `),
773+
})
774774

775775
for _, mode := range []ssa.BuilderMode{
776776
ssa.SanityCheckFunctions,
777777
ssa.SanityCheckFunctions | ssa.InstantiateGenerics,
778778
} {
779-
conf := loader.Config{
780-
Build: buildutil.FakeContext(pkgs),
781-
}
782-
conf.Import("main")
783779

784-
lprog, err := conf.Load()
785-
if err != nil {
786-
t.Errorf("Load failed: %s", err)
780+
pkgs := loadPackages(t, fsys, "example.com") // package main
781+
if len(pkgs) != 1 {
782+
t.Fatalf("Expected 1 root package but got %d", len(pkgs))
787783
}
788-
if lprog == nil {
789-
t.Fatalf("Load returned nil *Program")
784+
prog, _ := ssautil.Packages(pkgs, mode)
785+
p := prog.Package(pkgs[0].Types)
786+
p.Build()
787+
788+
if p.Pkg.Name() != "main" {
789+
t.Fatalf("Expected the second package is main but got %s", p.Pkg.Name())
790790
}
791-
// Create and build SSA
792-
prog := ssautil.CreateProgram(lprog, mode)
793-
p := prog.Package(lprog.Package("main").Pkg)
794791
p.Build()
795792

796793
var callees []string // callees of the CallInstruction.String() in main().
@@ -807,7 +804,7 @@ func TestGenericFunctionSelector(t *testing.T) {
807804
}
808805
sort.Strings(callees) // ignore the order in the code.
809806

810-
want := "[a.F[int] a.G[int string] a.H[int]]"
807+
want := "[example.com/a.F[int] example.com/a.G[int string] example.com/a.H[int]]"
811808
if got := fmt.Sprint(callees); got != want {
812809
t.Errorf("Expected main() to contain calls %v. got %v", want, got)
813810
}

0 commit comments

Comments
 (0)