diff --git a/go/types/testdata/decls0.src b/go/types/testdata/decls0.src index 9da75b90..f1df3ea7 100644 --- a/go/types/testdata/decls0.src +++ b/go/types/testdata/decls0.src @@ -190,10 +190,11 @@ func (S0) m2(x *S0 /* ERROR "field or method" */ .m2) {} func (S0) m3() (x S0 /* ERROR "field or method" */ .m3) { return } func (S0) m4() (x *S0 /* ERROR "field or method" */ .m4) { return } -// interfaces may have at most one blank method +// interfaces may not have any blank methods type BlankI interface { - _() - _ /* ERROR redeclared */ () + _ /* ERROR "invalid method name" */ () + _ /* ERROR "invalid method name" */ (float32) int + m() } // non-interface types may have multiple blank methods @@ -203,20 +204,3 @@ func (BlankT) _() {} func (BlankT) _(int) {} func (BlankT) _() int { return 0 } func (BlankT) _(int) int { return 0} - -// no type can ever satisfy an interface with a _ method -func _() { - var i BlankI - var x BlankT - i = x /* ERROR "cannot assign" */ - _ = i -} - -// assignability of interfaces with blank methods -func _() { - var x1, x1b interface { _() } - var x2 interface { _() } - x1 = x2 - _ = x1 - x1 = x1b -} \ No newline at end of file diff --git a/go/types/typexpr.go b/go/types/typexpr.go index 3c48c71c..f5a42cd2 100644 --- a/go/types/typexpr.go +++ b/go/types/typexpr.go @@ -472,6 +472,12 @@ func (check *checker) interfaceType(iface *Interface, ityp *ast.InterfaceType, d // and we don't care if a constructed AST has more. name := f.Names[0] pos := name.Pos() + // spec: "As with all method sets, in an interface type, + // each method must have a unique non-blank name." + if name.Name == "_" { + check.errorf(pos, "invalid method name _") + continue + } // Don't type-check signature yet - use an // empty signature now and update it later. // Since we know the receiver, set it up now @@ -483,10 +489,6 @@ func (check *checker) interfaceType(iface *Interface, ityp *ast.InterfaceType, d sig := new(Signature) sig.recv = NewVar(pos, check.pkg, "", recvTyp) m := NewFunc(pos, check.pkg, name.Name, sig) - // spec: "As with all method sets, in an interface type, - // each method must have a unique name." - // (The spec does not exclude blank _ identifiers for - // interface methods.) if check.declareInSet(&mset, pos, m) { iface.methods = append(iface.methods, m) iface.allMethods = append(iface.allMethods, m)