From cdd9e939ef28390ecb04c780499f1e3cc2195234 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 18 Jan 2022 22:30:03 -0800 Subject: [PATCH] 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 Run-TryBot: Robert Griesemer Reviewed-by: Robert Findley TryBot-Result: Gopher Robot --- src/cmd/compile/internal/types2/decl.go | 4 +++- src/cmd/compile/internal/types2/validtype.go | 2 +- src/go/types/decl.go | 4 +++- src/go/types/validtype.go | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cmd/compile/internal/types2/decl.go b/src/cmd/compile/internal/types2/decl.go index ab2983c80fb..41093cb6372 100644 --- a/src/cmd/compile/internal/types2/decl.go +++ b/src/cmd/compile/internal/types2/decl.go @@ -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) diff --git a/src/cmd/compile/internal/types2/validtype.go b/src/cmd/compile/internal/types2/validtype.go index 9cb427b44d8..c7f7c131698 100644 --- a/src/cmd/compile/internal/types2/validtype.go +++ b/src/cmd/compile/internal/types2/validtype.go @@ -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) } diff --git a/src/go/types/decl.go b/src/go/types/decl.go index a9e89464f67..043f02491d1 100644 --- a/src/go/types/decl.go +++ b/src/go/types/decl.go @@ -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) diff --git a/src/go/types/validtype.go b/src/go/types/validtype.go index d20a2b5bfaf..c0e6ee34f65 100644 --- a/src/go/types/validtype.go +++ b/src/go/types/validtype.go @@ -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) }