aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Findley <rfindley@google.com>2022-03-08 16:16:49 -0500
committerRobert Findley <rfindley@google.com>2022-03-22 13:07:38 +0000
commit2da1e47fb06bef29a99eaa1395ef1f7d11b05929 (patch)
treebad0c1b8e8088ee29ae7bfbbc0c21ed17a5b6617 /src
parenta8f019e956db40e9846e635a622489e356cb3c63 (diff)
downloadgo-2da1e47fb06bef29a99eaa1395ef1f7d11b05929.tar.xz
go/types, types: add additional generic cases for the Selections API
Change-Id: Icc5240db7447846061d0d81f5e15f788758d4d64 Reviewed-on: https://go-review.googlesource.com/c/go/+/393372 Trust: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/types2/api_test.go59
-rw-r--r--src/go/types/api_test.go59
2 files changed, 76 insertions, 42 deletions
diff --git a/src/cmd/compile/internal/types2/api_test.go b/src/cmd/compile/internal/types2/api_test.go
index 5bb551798e..d433ed1bdf 100644
--- a/src/cmd/compile/internal/types2/api_test.go
+++ b/src/cmd/compile/internal/types2/api_test.go
@@ -1428,15 +1428,23 @@ type C struct {
c int
}
+type G[P any] struct {
+ p P
+}
+
+func (G[P]) m(P) {}
+
+var Inst G[int]
+
func (C) g()
func (*C) h()
func main() {
// qualified identifiers
var _ lib.T
- _ = lib.C
- _ = lib.F
- _ = lib.V
+ _ = lib.C
+ _ = lib.F
+ _ = lib.V
_ = lib.T.M
// fields
@@ -1452,25 +1460,30 @@ func main() {
_ = A{}.c
_ = new(A).c
+ _ = Inst.p
+ _ = G[string]{}.p
+
// methods
- _ = A{}.f
- _ = new(A).f
- _ = A{}.g
- _ = new(A).g
- _ = new(A).h
+ _ = A{}.f
+ _ = new(A).f
+ _ = A{}.g
+ _ = new(A).g
+ _ = new(A).h
- _ = B{}.f
- _ = new(B).f
+ _ = B{}.f
+ _ = new(B).f
- _ = C{}.g
- _ = new(C).g
- _ = new(C).h
+ _ = C{}.g
+ _ = new(C).g
+ _ = new(C).h
+ _ = Inst.m
// method expressions
- _ = A.f
- _ = (*A).f
- _ = B.f
- _ = (*B).f
+ _ = A.f
+ _ = (*A).f
+ _ = B.f
+ _ = (*B).f
+ _ = G[string].m
}`
wantOut := map[string][2]string{
@@ -1484,6 +1497,7 @@ func main() {
"new(A).b": {"field (*main.A) b int", "->[0 0]"},
"A{}.c": {"field (main.A) c int", ".[1 0]"},
"new(A).c": {"field (*main.A) c int", "->[1 0]"},
+ "Inst.p": {"field (main.G[int]) p int", ".[0]"},
"A{}.f": {"method (main.A) f(int)", "->[0 0]"},
"new(A).f": {"method (*main.A) f(int)", "->[0 0]"},
@@ -1495,11 +1509,14 @@ func main() {
"C{}.g": {"method (main.C) g()", ".[0]"},
"new(C).g": {"method (*main.C) g()", "->[0]"},
"new(C).h": {"method (*main.C) h()", "->[1]"}, // TODO(gri) should this report .[1] ?
+ "Inst.m": {"method (main.G[int]) m(int)", ".[0]"},
- "A.f": {"method expr (main.A) f(main.A, int)", "->[0 0]"},
- "(*A).f": {"method expr (*main.A) f(*main.A, int)", "->[0 0]"},
- "B.f": {"method expr (main.B) f(main.B, int)", ".[0]"},
- "(*B).f": {"method expr (*main.B) f(*main.B, int)", "->[0]"},
+ "A.f": {"method expr (main.A) f(main.A, int)", "->[0 0]"},
+ "(*A).f": {"method expr (*main.A) f(*main.A, int)", "->[0 0]"},
+ "B.f": {"method expr (main.B) f(main.B, int)", ".[0]"},
+ "(*B).f": {"method expr (*main.B) f(*main.B, int)", "->[0]"},
+ "G[string].m": {"method expr (main.G[string]) m(main.G[string], string)", ".[0]"},
+ "G[string]{}.p": {"field (main.G[string]) p string", ".[0]"},
}
makePkg("lib", libSrc)
diff --git a/src/go/types/api_test.go b/src/go/types/api_test.go
index 4014201769..d25e6116cf 100644
--- a/src/go/types/api_test.go
+++ b/src/go/types/api_test.go
@@ -1432,15 +1432,23 @@ type C struct {
c int
}
+type G[P any] struct {
+ p P
+}
+
+func (G[P]) m(P) {}
+
+var Inst G[int]
+
func (C) g()
func (*C) h()
func main() {
// qualified identifiers
var _ lib.T
- _ = lib.C
- _ = lib.F
- _ = lib.V
+ _ = lib.C
+ _ = lib.F
+ _ = lib.V
_ = lib.T.M
// fields
@@ -1456,25 +1464,30 @@ func main() {
_ = A{}.c
_ = new(A).c
+ _ = Inst.p
+ _ = G[string]{}.p
+
// methods
- _ = A{}.f
- _ = new(A).f
- _ = A{}.g
- _ = new(A).g
- _ = new(A).h
+ _ = A{}.f
+ _ = new(A).f
+ _ = A{}.g
+ _ = new(A).g
+ _ = new(A).h
- _ = B{}.f
- _ = new(B).f
+ _ = B{}.f
+ _ = new(B).f
- _ = C{}.g
- _ = new(C).g
- _ = new(C).h
+ _ = C{}.g
+ _ = new(C).g
+ _ = new(C).h
+ _ = Inst.m
// method expressions
- _ = A.f
- _ = (*A).f
- _ = B.f
- _ = (*B).f
+ _ = A.f
+ _ = (*A).f
+ _ = B.f
+ _ = (*B).f
+ _ = G[string].m
}`
wantOut := map[string][2]string{
@@ -1488,6 +1501,7 @@ func main() {
"new(A).b": {"field (*main.A) b int", "->[0 0]"},
"A{}.c": {"field (main.A) c int", ".[1 0]"},
"new(A).c": {"field (*main.A) c int", "->[1 0]"},
+ "Inst.p": {"field (main.G[int]) p int", ".[0]"},
"A{}.f": {"method (main.A) f(int)", "->[0 0]"},
"new(A).f": {"method (*main.A) f(int)", "->[0 0]"},
@@ -1499,11 +1513,14 @@ func main() {
"C{}.g": {"method (main.C) g()", ".[0]"},
"new(C).g": {"method (*main.C) g()", "->[0]"},
"new(C).h": {"method (*main.C) h()", "->[1]"}, // TODO(gri) should this report .[1] ?
+ "Inst.m": {"method (main.G[int]) m(int)", ".[0]"},
- "A.f": {"method expr (main.A) f(main.A, int)", "->[0 0]"},
- "(*A).f": {"method expr (*main.A) f(*main.A, int)", "->[0 0]"},
- "B.f": {"method expr (main.B) f(main.B, int)", ".[0]"},
- "(*B).f": {"method expr (*main.B) f(*main.B, int)", "->[0]"},
+ "A.f": {"method expr (main.A) f(main.A, int)", "->[0 0]"},
+ "(*A).f": {"method expr (*main.A) f(*main.A, int)", "->[0 0]"},
+ "B.f": {"method expr (main.B) f(main.B, int)", ".[0]"},
+ "(*B).f": {"method expr (*main.B) f(*main.B, int)", "->[0]"},
+ "G[string].m": {"method expr (main.G[string]) m(main.G[string], string)", ".[0]"},
+ "G[string]{}.p": {"field (main.G[string]) p string", ".[0]"},
}
makePkg("lib", libSrc)