If an interface contains a blank method, that's already an error. No
need for useless follow-up error messages about not implementing them.
Fixes #42964.
Change-Id: I5bf53a8f27d75d4c86c61588c5e2e3e95563d320
Reviewed-on: https://go-review.googlesource.com/c/go/+/275294
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
}
}
-// declare the arguments in an
-// interface field declaration.
-func ifacedcl(n *ir.Field) {
- if n.Sym == nil {
- base.Fatalf("ifacedcl")
- }
-
- if n.Sym.IsBlank() {
- base.Errorf("methods must have a unique non-blank name")
- }
-}
-
// declare the function proper
// and declare the arguments.
// called in extern-declaration context
n = ir.NewField(p.pos(method), nil, importName(p.packname(method.Type)).(ir.Ntype), nil)
} else {
mname := p.name(method.Name)
+ if mname.IsBlank() {
+ base.Errorf("methods must have a unique non-blank name")
+ continue
+ }
sig := p.typeExpr(method.Type).(*ir.FuncType)
sig.Recv = fakeRecv()
n = ir.NewField(p.pos(method), mname, sig, nil)
- ifacedcl(n)
}
l = append(l, n)
}
func (t *T2) M() {}
func (t *T2) _() {}
-// Check that nothing satisfies an interface with blank methods.
-var b1 B1 = &T2{} // ERROR "incompatible|missing _ method"
-var b2 B2 = &T2{} // ERROR "incompatible|missing _ method"
+// Already reported about the invalid blank interface method above;
+// no need to report about not implementing it.
+var b1 B1 = &T2{}
+var b2 B2 = &T2{}