mirror of
https://github.com/golang/go
synced 2024-11-22 23:50:03 -07:00
cmd/compile: print expression for invalid operation errors
For #48472 Change-Id: I5072ebcf53e03fb5515c51a2ad01f02d72b30719 Reviewed-on: https://go-review.googlesource.com/c/go/+/350929 Reviewed-by: Robert Griesemer <gri@golang.org> Trust: David Chase <drchase@google.com>
This commit is contained in:
parent
aeea5bacbf
commit
ff8a7e513b
@ -1019,7 +1019,7 @@ func (check *Checker) binary(x *operand, e syntax.Expr, lhs, rhs syntax.Expr, op
|
||||
// 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+"mismatched types %s and %s", x.typ, y.typ)
|
||||
check.errorf(x, invalidOp+"%s (mismatched types %s and %s)", e, x.typ, y.typ)
|
||||
}
|
||||
x.mode = invalid
|
||||
return
|
||||
|
11
src/cmd/compile/internal/types2/testdata/fixedbugs/issue48472.go2
vendored
Normal file
11
src/cmd/compile/internal/types2/testdata/fixedbugs/issue48472.go2
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func g() {
|
||||
var s string
|
||||
var i int
|
||||
_ = s /* ERROR invalid operation: s \+ i \(mismatched types string and int\) */ + i
|
||||
}
|
@ -994,7 +994,7 @@ func (check *Checker) binary(x *operand, e ast.Expr, lhs, rhs ast.Expr, op token
|
||||
if e != nil {
|
||||
posn = e
|
||||
}
|
||||
check.invalidOp(posn, _MismatchedTypes, "mismatched types %s and %s", x.typ, y.typ)
|
||||
check.invalidOp(posn, _MismatchedTypes, "%s (mismatched types %s and %s)", e, x.typ, y.typ)
|
||||
}
|
||||
x.mode = invalid
|
||||
return
|
||||
|
11
src/go/types/testdata/fixedbugs/issue48472.go2
vendored
Normal file
11
src/go/types/testdata/fixedbugs/issue48472.go2
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
func g() {
|
||||
var s string
|
||||
var i int
|
||||
_ = s /* ERROR invalid operation: s \+ i \(mismatched types string and int\) */ + i
|
||||
}
|
Loading…
Reference in New Issue
Block a user