[dev.typeparams] cmd/compile/internal/types: adjust some error messages to match the compiler

Change-Id: I04bd7b294de4ed0fb01bc0609e09debea2d797bd
Reviewed-on: https://go-review.googlesource.com/c/go/+/274974
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Robert Griesemer 2020-12-01 17:37:12 -08:00
parent 6b4da14dd3
commit 07d32c8183
3 changed files with 11 additions and 3 deletions

View file

@ -1867,7 +1867,11 @@ func (check *Checker) typeAssertion(pos syntax.Pos, x *operand, xtyp *Interface,
} else {
msg = "missing method " + method.name
}
check.errorf(pos, "%s cannot have dynamic type %s (%s)", x, T, msg)
if check.conf.CompilerErrorMessages {
check.errorf(pos, "impossible type assertion: %s (%s)", x, msg)
} else {
check.errorf(pos, "%s cannot have dynamic type %s (%s)", x, T, msg)
}
}
// expr typechecks expression e and initializes x with the expression value.

View file

@ -886,7 +886,7 @@ func rangeKeyVal(typ Type, wantKey, wantVal bool) (Type, Type, string) {
case *Chan:
var msg string
if typ.dir == SendOnly {
msg = "send-only channel"
msg = "receive from send-only channel"
}
return typ.elem, Typ[Invalid], msg
case *Sum:

View file

@ -806,7 +806,11 @@ func (check *Checker) interfaceType(ityp *Interface, iface *syntax.InterfaceType
// of a type list (f.Name.Value == "type").
name := f.Name.Value
if name == "_" {
check.errorf(f.Name, "invalid method name _")
if check.conf.CompilerErrorMessages {
check.errorf(f.Name, "methods must have a unique non-blank name")
} else {
check.errorf(f.Name, "invalid method name _")
}
continue // ignore
}