mirror of
https://github.com/golang/go
synced 2024-11-26 17:16:54 -07:00
go/types, types2: consistently set x.mode in Checker.assignment
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>
This commit is contained in:
parent
a41a29ad19
commit
6a5f35047f
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user