From: Cuong Manh Le Date: Wed, 20 Oct 2021 05:31:53 +0000 (+0700) Subject: go/types: print assignment operation for invalid operation errors X-Git-Tag: go1.18beta1~815 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fca46d0b36c10250713ec0f4c9bf13d626f358d1;p=gostls13.git 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 Run-TryBot: Cuong Manh Le TryBot-Result: Go Bot Reviewed-by: Robert Findley --- diff --git a/src/go/types/expr.go b/src/go/types/expr.go index fac5a5e31d..3a09dfd85f 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -1000,7 +1000,11 @@ func (check *Checker) binary(x *operand, e ast.Expr, lhs, rhs ast.Expr, op token 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 5fefcaf22b..2d908f4c8b 100644 --- a/src/go/types/testdata/fixedbugs/issue48472.go2 +++ b/src/go/types/testdata/fixedbugs/issue48472.go2 @@ -9,3 +9,8 @@ func g() { 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 +}