1
0
mirror of https://github.com/golang/go synced 2024-11-24 17:20:12 -07:00

go/types, types2: alias type declarations may refer to constraint types

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>
This commit is contained in:
Robert Griesemer 2022-03-14 12:10:11 -07:00
parent 63c7614fd0
commit 3ebb1720d9
4 changed files with 40 additions and 2 deletions

View File

@ -502,7 +502,7 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *syntax.TypeDecl, def *Named
} }
check.brokenAlias(obj) check.brokenAlias(obj)
rhs = check.varType(tdecl.Type) rhs = check.typ(tdecl.Type)
check.validAlias(obj, rhs) check.validAlias(obj, rhs)
return return
} }

View File

@ -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}
)

View File

@ -559,7 +559,7 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *ast.TypeSpec, def *Named) {
} }
check.brokenAlias(obj) check.brokenAlias(obj)
rhs = check.varType(tdecl.Type) rhs = check.typ(tdecl.Type)
check.validAlias(obj, rhs) check.validAlias(obj, rhs)
return return
} }

View File

@ -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}
)