]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: print assignment operation for invalid operation errors
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 20 Oct 2021 05:31:53 +0000 (12:31 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Thu, 21 Oct 2021 02:35:47 +0000 (02:35 +0000)
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>
src/go/types/expr.go
src/go/types/testdata/fixedbugs/issue48472.go2

index fac5a5e31d46f79aceb482ea8f5038ea3d60e91c..3a09dfd85f9b72cc0550c0502f5abeea3054c253 100644 (file)
@@ -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
index 5fefcaf22bcfa881ada7008a74bdc744c59564da..2d908f4c8b56c7c6ab799080a5c863bfd5a234d5 100644 (file)
@@ -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
+}