From 7751883379621d8ecbf7e4920af0a81c31f2c078 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 16 Mar 2022 14:09:56 -0700 Subject: [PATCH] go/types, types2: ensure we have a fully resolved type in validType This addresses a situation where Named.fromRHS is nil which is causing validType to panic when the debug flag is set. Change-Id: Ie1af3f4d412efc2ce2ee7707af5375ed130a1f2a Reviewed-on: https://go-review.googlesource.com/c/go/+/393436 Trust: Robert Griesemer Reviewed-by: Robert Findley --- src/cmd/compile/internal/types2/validtype.go | 3 ++- src/go/types/validtype.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cmd/compile/internal/types2/validtype.go b/src/cmd/compile/internal/types2/validtype.go index f365ad1e27..c7d42551dd 100644 --- a/src/cmd/compile/internal/types2/validtype.go +++ b/src/cmd/compile/internal/types2/validtype.go @@ -63,7 +63,8 @@ func (check *Checker) validType0(typ Type, env *tparamEnv, path []Object) typeIn case *Named: // Don't report a 2nd error if we already know the type is invalid // (e.g., if a cycle was detected earlier, via under). - if t.underlying == Typ[Invalid] { + // Note: ensure that t.orig is fully resolved by calling Underlying(). + if t.Underlying() == Typ[Invalid] { check.infoMap[t] = invalid return invalid } diff --git a/src/go/types/validtype.go b/src/go/types/validtype.go index 7d7029bce2..2c686f2655 100644 --- a/src/go/types/validtype.go +++ b/src/go/types/validtype.go @@ -62,8 +62,8 @@ func (check *Checker) validType0(typ Type, env *tparamEnv, path []Object) typeIn case *Named: // Don't report a 2nd error if we already know the type is invalid - // (e.g., if a cycle was detected earlier, via under). - if t.underlying == Typ[Invalid] { + // Note: ensure that t.orig is fully resolved by calling Underlying(). + if t.Underlying() == Typ[Invalid] { check.infoMap[t] = invalid return invalid } -- 2.50.0