From 2e6e9df2c1242274b02b584c617947aeed39c398 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 16 Dec 2021 10:50:34 -0800 Subject: [PATCH] go/types, types2: use compiler error message for undefined operators For #48712. Change-Id: I1596fe8688f093e0e92cf5b8d5501aac8631324e Reviewed-on: https://go-review.googlesource.com/c/go/+/372894 Trust: Robert Griesemer Run-TryBot: Robert Griesemer Reviewed-by: Robert Findley TryBot-Result: Gopher Robot --- src/cmd/compile/internal/types2/expr.go | 12 ++---------- src/go/types/expr.go | 4 ++-- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/cmd/compile/internal/types2/expr.go b/src/cmd/compile/internal/types2/expr.go index 5961f32f37..3e3104abb6 100644 --- a/src/cmd/compile/internal/types2/expr.go +++ b/src/cmd/compile/internal/types2/expr.go @@ -73,11 +73,7 @@ func init() { func (check *Checker) op(m opPredicates, x *operand, op syntax.Operator) bool { if pred := m[op]; pred != nil { if !pred(x.typ) { - if check.conf.CompilerErrorMessages { - check.errorf(x, invalidOp+"operator %s not defined on %s", op, x) - } else { - check.errorf(x, invalidOp+"operator %s not defined for %s", op, x) - } + check.errorf(x, invalidOp+"operator %s not defined on %s", op, x) return false } } else { @@ -790,11 +786,7 @@ func (check *Checker) comparison(x, y *operand, op syntax.Operator) { if x.isNil() { typ = y.typ } - if check.conf.CompilerErrorMessages { - err = check.sprintf("operator %s not defined on %s", op, typ) - } else { - err = check.sprintf("operator %s not defined for %s", op, typ) - } + err = check.sprintf("operator %s not defined on %s", op, typ) } } else { err = check.sprintf("mismatched types %s and %s", x.typ, y.typ) diff --git a/src/go/types/expr.go b/src/go/types/expr.go index 452e9ab598..8ddfb8de7e 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -74,7 +74,7 @@ func init() { func (check *Checker) op(m opPredicates, x *operand, op token.Token) bool { if pred := m[op]; pred != nil { if !pred(x.typ) { - check.invalidOp(x, _UndefinedOp, "operator %s not defined for %s", op, x) + check.invalidOp(x, _UndefinedOp, "operator %s not defined on %s", op, x) return false } } else { @@ -745,7 +745,7 @@ func (check *Checker) comparison(x, y *operand, op token.Token) { if x.isNil() { typ = y.typ } - err = check.sprintf("operator %s not defined for %s", op, typ) + err = check.sprintf("operator %s not defined on %s", op, typ) code = _UndefinedOp } } else { -- 2.50.0