]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: adjust type-checking of pointer types
authorRobert Griesemer <gri@golang.org>
Tue, 12 Nov 2024 22:14:19 +0000 (14:14 -0800)
committerGopher Robot <gobot@golang.org>
Wed, 13 Nov 2024 17:15:38 +0000 (17:15 +0000)
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>
src/go/types/typexpr.go

index c83f53ba615406d8a53dd27d61072889adcf2032..0b88f31d73f44bf0947f5dbf49fb38125d574947 100644 (file)
@@ -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: