Skip to content

Commit

Permalink
go/types, types2: better error message for blank interface method nam…
Browse files Browse the repository at this point in the history
…e (cleanup)

Use the 1.17 compiler error message.

Change-Id: Ic62de5bfc9681674069934afc590f5840729f8e2
Reviewed-on: https://go-review.googlesource.com/c/go/+/396297
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
  • Loading branch information
griesemer committed Mar 29, 2022
1 parent 9038c24 commit f71daa6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/cmd/compile/internal/types2/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ func (check *Checker) interfaceType(ityp *Interface, iface *syntax.InterfaceType
// We have a method with name f.Name.
name := f.Name.Value
if name == "_" {
if check.conf.CompilerErrorMessages {
check.error(f.Name, "methods must have a unique non-blank name")
} else {
check.error(f.Name, "invalid method name _")
}
check.error(f.Name, "methods must have a unique non-blank name")
continue // ignore
}

Expand Down
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/types2/testdata/check/decls0.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ func (S0) m4() (x *S0 /* ERROR illegal cycle in method declaration */ .m4) { ret

// interfaces may not have any blank methods
type BlankI interface {
_ /* ERROR "invalid method name" */ ()
_ /* ERROR "invalid method name" */ (float32) int
_ /* ERROR "methods must have a unique non-blank name" */ ()
_ /* ERROR "methods must have a unique non-blank name" */ (float32) int
m()
}

Expand Down
2 changes: 1 addition & 1 deletion src/go/types/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (check *Checker) interfaceType(ityp *Interface, iface *ast.InterfaceType, d
// We have a method with name f.Names[0].
name := f.Names[0]
if name.Name == "_" {
check.errorf(name, _BlankIfaceMethod, "invalid method name _")
check.errorf(name, _BlankIfaceMethod, "methods must have a unique non-blank name")
continue // ignore
}

Expand Down
4 changes: 2 additions & 2 deletions src/go/types/testdata/check/decls0.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ func (S0) m4 () (x *S0 /* ERROR illegal cycle in method declaration */ .m4) { re

// interfaces may not have any blank methods
type BlankI interface {
_ /* ERROR "invalid method name" */ ()
_ /* ERROR "invalid method name" */ (float32) int
_ /* ERROR "methods must have a unique non-blank name" */ ()
_ /* ERROR "methods must have a unique non-blank name" */ (float32) int
m()
}

Expand Down

0 comments on commit f71daa6

Please sign in to comment.