]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: consistently set x.mode in Checker.assignment
authorRobert Griesemer <gri@golang.org>
Tue, 18 Apr 2023 17:20:15 +0000 (10:20 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 18 Apr 2023 23:15:05 +0000 (23:15 +0000)
Per the doc string, Checker.assignment must set x.mode to invalid
in case of failure.

(It may be simpler to return a bool, but the operand x may be tested
by callers several stack frames above.)

Change-Id: Ia1789b0396e8338103c0e707761c46f8d253fd31
Reviewed-on: https://go-review.googlesource.com/c/go/+/485875
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
src/cmd/compile/internal/types2/assignments.go
src/go/types/assignments.go

index 02823fed2c6479a5230632c2c6d909a665ed1f5e..30ed9ae701ccd471ee14f3e928c04ef2f9ebadde 100644 (file)
@@ -30,6 +30,7 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
                // we may get here because of other problems (go.dev/issue/39634, crash 12)
                // TODO(gri) do we need a new "generic" error code here?
                check.errorf(x, IncompatibleAssign, "cannot assign %s to %s in %s", x, T, context)
+               x.mode = invalid
                return
        }
 
@@ -78,6 +79,8 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
        // A generic (non-instantiated) function value cannot be assigned to a variable.
        if sig, _ := under(x.typ).(*Signature); sig != nil && sig.TypeParams().Len() > 0 {
                check.errorf(x, WrongTypeArgCount, "cannot use generic function %s without instantiation in %s", x, context)
+               x.mode = invalid
+               return
        }
 
        // spec: "If a left-hand side is the blank identifier, any typed or
index 68b07a717227773d0781c54983cd0805163e4525..71fbbea46ff48433bd4d03c9a547f8f34ff2fe11 100644 (file)
@@ -30,6 +30,7 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
                // we may get here because of other problems (go.dev/issue/39634, crash 12)
                // TODO(gri) do we need a new "generic" error code here?
                check.errorf(x, IncompatibleAssign, "cannot assign %s to %s in %s", x, T, context)
+               x.mode = invalid
                return
        }
 
@@ -76,6 +77,8 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
        // A generic (non-instantiated) function value cannot be assigned to a variable.
        if sig, _ := under(x.typ).(*Signature); sig != nil && sig.TypeParams().Len() > 0 {
                check.errorf(x, WrongTypeArgCount, "cannot use generic function %s without instantiation in %s", x, context)
+               x.mode = invalid
+               return
        }
 
        // spec: "If a left-hand side is the blank identifier, any typed or