diff options
author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2021-06-17 10:14:07 +0700 |
---|---|---|
committer | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2021-06-18 02:07:04 +0000 |
commit | 2a7900762c24a4b04d0d51c833e22bc319d0234e (patch) | |
tree | 644d854026fdf45f1c836ece6fa1612818586de1 /src/go/types/expr.go | |
parent | 90096f445eaf78b954b9d37c47d137d4fcbd272c (diff) | |
download | go-2a7900762c24a4b04d0d51c833e22bc319d0234e.tar.gz go-2a7900762c24a4b04d0d51c833e22bc319d0234e.zip |
[dev.typeparams] go/types: report better error for invalid untyped operation
This is port of CL 328053 for types2 to go/type.
The change is identical, but for some tweaks to the error positions in
tests.
Updates #46749
Change-Id: I8d34c5b1669e59e4ec7d91f81dcf655b2bfd89a5
Reviewed-on: https://go-review.googlesource.com/c/go/+/328869
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/go/types/expr.go')
-rw-r--r-- | src/go/types/expr.go | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/go/types/expr.go b/src/go/types/expr.go index b7cc6e8ae7..402d96f66a 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -927,14 +927,28 @@ func (check *Checker) binary(x *operand, e ast.Expr, lhs, rhs ast.Expr, op token return } - check.convertUntyped(x, y.typ) - if x.mode == invalid { - return + canMix := func(x, y *operand) bool { + if IsInterface(x.typ) || IsInterface(y.typ) { + return true + } + if isBoolean(x.typ) != isBoolean(y.typ) { + return false + } + if isString(x.typ) != isString(y.typ) { + return false + } + return true } - check.convertUntyped(&y, x.typ) - if y.mode == invalid { - x.mode = invalid - return + if canMix(x, &y) { + check.convertUntyped(x, y.typ) + if x.mode == invalid { + return + } + check.convertUntyped(&y, x.typ) + if y.mode == invalid { + x.mode = invalid + return + } } if isComparison(op) { |