Skip to content

Commit fca46d0

Browse files
committed
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 <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 73652af commit fca46d0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/go/types/expr.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,11 @@ func (check *Checker) binary(x *operand, e ast.Expr, lhs, rhs ast.Expr, op token
10001000
if e != nil {
10011001
posn = e
10021002
}
1003-
check.invalidOp(posn, _MismatchedTypes, "%s (mismatched types %s and %s)", e, x.typ, y.typ)
1003+
if e != nil {
1004+
check.invalidOp(posn, _MismatchedTypes, "%s (mismatched types %s and %s)", e, x.typ, y.typ)
1005+
} else {
1006+
check.invalidOp(posn, _MismatchedTypes, "%s %s= %s (mismatched types %s and %s)", lhs, op, rhs, x.typ, y.typ)
1007+
}
10041008
}
10051009
x.mode = invalid
10061010
return

src/go/types/testdata/fixedbugs/issue48472.go2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ func g() {
99
var i int
1010
_ = s /* ERROR invalid operation: s \+ i \(mismatched types string and int\) */ + i
1111
}
12+
13+
func f(i int) int {
14+
i /* ERROR invalid operation: i \+= "1" \(mismatched types int and untyped string\) */ += "1"
15+
return i
16+
}

0 commit comments

Comments
 (0)