go.tools/go/types: report identifier for methods with blank names

R=adonovan
CC=golang-dev
https://golang.org/cl/12123045
This commit is contained in:
Robert Griesemer 2013-07-30 12:47:40 -07:00
parent 2a3a12930b
commit 33d57bf48f
2 changed files with 15 additions and 12 deletions

View File

@ -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)
}
}
}

View File

@ -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 {} }