]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types, types2: alias type declarations may refer to constraint types
authorRobert Griesemer <gri@golang.org>
Mon, 14 Mar 2022 19:10:11 +0000 (12:10 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 21 Mar 2022 19:10:10 +0000 (19:10 +0000)
Fixes #51616.

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

index 579fa55e5911888b06090503f0ef95f5e1f37664..01c47ee7c19dc39dd67b826ef6f5e8c7bea5d16a 100644 (file)
@@ -502,7 +502,7 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *syntax.TypeDecl, def *Named
                }
 
                check.brokenAlias(obj)
-               rhs = check.varType(tdecl.Type)
+               rhs = check.typ(tdecl.Type)
                check.validAlias(obj, rhs)
                return
        }
diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51616.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51616.go2
new file mode 100644 (file)
index 0000000..e0efc9e
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2022 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 (
+        C[T any] interface{~int; M() T}
+
+        _ C[bool]
+        _ comparable
+        _ interface {~[]byte | ~string}
+
+        // Alias type declarations may refer to "constraint" types
+        // like ordinary type declarations.
+        _ = C[bool]
+        _ = comparable
+        _ = interface {~[]byte | ~string}
+)
index 93a37d76ce0d78021708de8ae7806e41f205d85a..c3d43d93f6b10bed0c5677d89c6ed97b9f056942 100644 (file)
@@ -559,7 +559,7 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *ast.TypeSpec, def *Named) {
                }
 
                check.brokenAlias(obj)
-               rhs = check.varType(tdecl.Type)
+               rhs = check.typ(tdecl.Type)
                check.validAlias(obj, rhs)
                return
        }
diff --git a/src/go/types/testdata/fixedbugs/issue51616.go2 b/src/go/types/testdata/fixedbugs/issue51616.go2
new file mode 100644 (file)
index 0000000..e0efc9e
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2022 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 (
+        C[T any] interface{~int; M() T}
+
+        _ C[bool]
+        _ comparable
+        _ interface {~[]byte | ~string}
+
+        // Alias type declarations may refer to "constraint" types
+        // like ordinary type declarations.
+        _ = C[bool]
+        _ = comparable
+        _ = interface {~[]byte | ~string}
+)