Skip to content

Commit

Permalink
[dev.typeparams] cmd/compile/internal/types: adjust some error messag…
Browse files Browse the repository at this point in the history
…es 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>
  • Loading branch information
griesemer committed Dec 3, 2020
1 parent 6b4da14 commit 07d32c8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/cmd/compile/internal/types2/expr.go
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/types2/stmt.go
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion src/cmd/compile/internal/types2/typexpr.go
Expand Up @@ -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
}

Expand Down

0 comments on commit 07d32c8

Please sign in to comment.