go/types: print assignment operation for invalid operation errors
This is port of CL 357229 for types2 to go/types.
Change-Id: I35ed6b784969210a00ea5b36238df7d6b7fa18bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/357230
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 Findley <rfindley@google.com>
diff --git a/src/go/types/expr.go b/src/go/types/expr.go
index fac5a5e..3a09dfd 100644
--- a/src/go/types/expr.go
+++ b/src/go/types/expr.go
@@ -1000,7 +1000,11 @@
if e != nil {
posn = e
}
- check.invalidOp(posn, _MismatchedTypes, "%s (mismatched types %s and %s)", e, x.typ, y.typ)
+ if e != nil {
+ check.invalidOp(posn, _MismatchedTypes, "%s (mismatched types %s and %s)", e, x.typ, y.typ)
+ } else {
+ check.invalidOp(posn, _MismatchedTypes, "%s %s= %s (mismatched types %s and %s)", lhs, op, rhs, x.typ, y.typ)
+ }
}
x.mode = invalid
return
diff --git a/src/go/types/testdata/fixedbugs/issue48472.go2 b/src/go/types/testdata/fixedbugs/issue48472.go2
index 5fefcaf..2d908f4 100644
--- a/src/go/types/testdata/fixedbugs/issue48472.go2
+++ b/src/go/types/testdata/fixedbugs/issue48472.go2
@@ -9,3 +9,8 @@
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
+}