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:
parent
2a3a12930b
commit
33d57bf48f
|
|
@ -294,9 +294,8 @@ 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 != "_" {
|
||||
// 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 {
|
||||
|
|
@ -307,7 +306,6 @@ func (check *checker) resolveFiles(files []*ast.File) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
objList = append(objList, obj)
|
||||
objMap[obj] = declInfo{scope, nil, nil, d}
|
||||
|
||||
|
|
@ -547,9 +545,13 @@ 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)
|
||||
// Methods with blank _ names cannot be found.
|
||||
// Don't add them to the method list.
|
||||
if m.name != "_" {
|
||||
named.methods = append(named.methods, m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete(check.methods, obj.name) // we don't need them anymore
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {} }
|
||||
|
|
|
|||
Loading…
Reference in New Issue