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 <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
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: