]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: union terms must be instantiated
authorRobert Griesemer <gri@golang.org>
Tue, 31 Aug 2021 01:07:54 +0000 (18:07 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 31 Aug 2021 16:20:54 +0000 (16:20 +0000)
Fixes #48083.

Change-Id: I77899d3e6edc806dee770403b3c3c4e2974d0e50
Reviewed-on: https://go-review.googlesource.com/c/go/+/346293
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/testdata/fixedbugs/issue48083.go2 [new file with mode: 0644]
src/cmd/compile/internal/types2/union.go
src/go/types/testdata/fixedbugs/issue48083.go2 [new file with mode: 0644]
src/go/types/union.go

diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue48083.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue48083.go2
new file mode 100644 (file)
index 0000000..3dae514
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+type T[P any] struct{}
+
+type _ interface{ int | T /* ERROR cannot use generic type */ }
\ No newline at end of file
index 933e5a295185530169bd2a101436795ac0f54bae..d4c749a89b9e956a0964e91196990c5c82df2fbb 100644 (file)
@@ -122,7 +122,7 @@ func parseTilde(check *Checker, x syntax.Expr) (tilde bool, typ Type) {
                x = op.X
                tilde = true
        }
-       typ = check.anyType(x)
+       typ = check.typ(x)
        // embedding stand-alone type parameters is not permitted (issue #47127).
        if _, ok := under(typ).(*TypeParam); ok {
                check.error(x, "cannot embed a type parameter")
diff --git a/src/go/types/testdata/fixedbugs/issue48083.go2 b/src/go/types/testdata/fixedbugs/issue48083.go2
new file mode 100644 (file)
index 0000000..3dae514
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+type T[P any] struct{}
+
+type _ interface{ int | T /* ERROR cannot use generic type */ }
\ No newline at end of file
index 1ba99adaca2c02a65ef7711bd7e9c9af475e32c4..f6b32b9e5df0450ae688f9db7616e8ba9c05b66c 100644 (file)
@@ -125,7 +125,7 @@ func parseTilde(check *Checker, x ast.Expr) (tilde bool, typ Type) {
                x = op.X
                tilde = true
        }
-       typ = check.anyType(x)
+       typ = check.typ(x)
        // embedding stand-alone type parameters is not permitted (issue #47127).
        if _, ok := under(typ).(*TypeParam); ok {
                check.error(x, _Todo, "cannot embed a type parameter")