When invoking check.binary for assignment operation, the expression will
be nil, thus for printing the assignment operation error message, we
need to reconstruct the statement from lhs, op, rhs.
Fixes #48472
Change-Id: Ie38c3dd8069b47e508968d6e43cedcf7536559ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/357229
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
// only report an error if we have valid types
// (otherwise we had an error reported elsewhere already)
if x.typ != Typ[Invalid] && y.typ != Typ[Invalid] {
- check.errorf(x, invalidOp+"%s (mismatched types %s and %s)", e, x.typ, y.typ)
+ if e != nil {
+ check.errorf(x, invalidOp+"%s (mismatched types %s and %s)", e, x.typ, y.typ)
+ } else {
+ check.errorf(x, invalidOp+"%s %s= %s (mismatched types %s and %s)", lhs, op, rhs, x.typ, y.typ)
+ }
}
x.mode = invalid
return
var i int
_ = s /* ERROR invalid operation: s \+ i \(mismatched types string and int\) */ + i
}
+
+func f(i int) int {
+ i /* ERROR invalid operation: i \+= "1" \(mismatched types int and untyped string\) */ += "1"
+ return i
+}