From 5e91059f8b5cc078b4b0bfa38290a98414e441e2 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 12 Nov 2024 14:14:19 -0800 Subject: [PATCH] go/types: adjust type-checking of pointer types This matches the behavior of types2. For #49005. Change-Id: I45661c96124f1c75c4fb6f69cbba7c73984a8231 Reviewed-on: https://go-review.googlesource.com/c/go/+/626039 Auto-Submit: Robert Griesemer LUCI-TryBot-Result: Go LUCI Reviewed-by: Robert Griesemer Reviewed-by: Robert Findley --- src/go/types/typexpr.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/go/types/typexpr.go b/src/go/types/typexpr.go index c83f53ba61..0b88f31d73 100644 --- a/src/go/types/typexpr.go +++ b/src/go/types/typexpr.go @@ -334,6 +334,13 @@ func (check *Checker) typInternal(e0 ast.Expr, def *TypeName) (T Type) { typ.base = Typ[Invalid] // avoid nil base in invalid recursive type declaration setDefType(def, typ) typ.base = check.varType(e.X) + // If typ.base is invalid, it's unlikely that *base is particularly + // useful - even a valid dereferenciation will lead to an invalid + // type again, and in some cases we get unexpected follow-on errors + // (e.g., go.dev/issue/49005). Return an invalid type instead. + if !isValid(typ.base) { + return Typ[Invalid] + } return typ case *ast.FuncType: -- 2.48.1