diff --git a/go/types/resolver.go b/go/types/resolver.go index 5666975e..04663c45 100644 --- a/go/types/resolver.go +++ b/go/types/resolver.go @@ -294,17 +294,15 @@ func (check *checker) resolveFiles(files []*ast.File) { } else { // Associate method with receiver base type name, if possible. // Ignore methods that have an invalid receiver, or a blank _ - // receiver or method name. They will be type-checked later, - // with non-method functions. - if obj.name != "_" { - if list := d.Recv.List; len(list) > 0 { - typ := list[0].Type - if ptr, _ := typ.(*ast.StarExpr); ptr != nil { - typ = ptr.X - } - if base, _ := typ.(*ast.Ident); base != nil && base.Name != "_" { - check.methods[base.Name] = append(check.methods[base.Name], obj) - } + // receiver name. They will be type-checked later, with regular + // functions. + if list := d.Recv.List; len(list) > 0 { + typ := list[0].Type + if ptr, _ := typ.(*ast.StarExpr); ptr != nil { + typ = ptr.X + } + if base, _ := typ.(*ast.Ident); base != nil && base.Name != "_" { + check.methods[base.Name] = append(check.methods[base.Name], obj) } } } @@ -547,7 +545,11 @@ func (check *checker) typeDecl(obj *TypeName, typ ast.Expr, def *Named, cycleOk // and collect it with the named base type. if m != nil { check.objDecl(m, nil, true) - named.methods = append(named.methods, m) + // Methods with blank _ names cannot be found. + // Don't add them to the method list. + if m.name != "_" { + named.methods = append(named.methods, m) + } } } diff --git a/go/types/resolver_test.go b/go/types/resolver_test.go index 99bf62ec..7e062b92 100644 --- a/go/types/resolver_test.go +++ b/go/types/resolver_test.go @@ -43,6 +43,7 @@ var sources = []string{ type I interface{ m() } var _ = T{a: 1, b: 2, c: 3} func (_ T) m() {} + func (T) _() {} var i I var _ = i.m func _(s []int) { for i, x := range s {} }