1
0
mirror of https://github.com/golang/go synced 2024-11-24 04:30:14 -07:00

go/types, types2: validType argument must be *Named type

Now that we have a separate top-level entry point for validType
we can use the more narrow type *Named (instead of Type) for its
argument.

Preparation for fixing issue #48962.

Change-Id: I93aee4abc87036c6a68323dc970efe8e617a9103
Reviewed-on: https://go-review.googlesource.com/c/go/+/379434
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Robert Griesemer 2022-01-18 22:30:03 -08:00
parent 4284d45553
commit cdd9e939ef
4 changed files with 8 additions and 4 deletions

View File

@ -477,7 +477,9 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *syntax.TypeDecl, def *Named
var rhs Type
check.later(func() {
check.validType(obj.typ)
if t, _ := obj.typ.(*Named); t != nil { // type may be invalid
check.validType(t)
}
// If typ is local, an error was already reported where typ is specified/defined.
if check.isImportedConstraint(rhs) && !check.allowVersion(check.pkg, 1, 18) {
check.versionErrorf(tdecl.Type, "go1.18", "using type constraint %s", rhs)

View File

@ -9,7 +9,7 @@ package types2
// defined types.
// (Cycles involving alias types, as in "type A = [10]A" are detected
// earlier, via the objDecl cycle detection mechanism.)
func (check *Checker) validType(typ Type) {
func (check *Checker) validType(typ *Named) {
check.validType0(typ, nil)
}

View File

@ -530,7 +530,9 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *ast.TypeSpec, def *Named) {
var rhs Type
check.later(func() {
check.validType(obj.typ)
if t, _ := obj.typ.(*Named); t != nil { // type may be invalid
check.validType(t)
}
// If typ is local, an error was already reported where typ is specified/defined.
if check.isImportedConstraint(rhs) && !check.allowVersion(check.pkg, 1, 18) {
check.errorf(tdecl.Type, _UnsupportedFeature, "using type constraint %s requires go1.18 or later", rhs)

View File

@ -9,7 +9,7 @@ package types
// defined types.
// (Cycles involving alias types, as in "type A = [10]A" are detected
// earlier, via the objDecl cycle detection mechanism.)
func (check *Checker) validType(typ Type) {
func (check *Checker) validType(typ *Named) {
check.validType0(typ, nil)
}