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 {
|
} else {
|
||||||
// Associate method with receiver base type name, if possible.
|
// Associate method with receiver base type name, if possible.
|
||||||
// Ignore methods that have an invalid receiver, or a blank _
|
// Ignore methods that have an invalid receiver, or a blank _
|
||||||
// receiver or method name. They will be type-checked later,
|
// receiver name. They will be type-checked later, with regular
|
||||||
// with non-method functions.
|
// functions.
|
||||||
if obj.name != "_" {
|
|
||||||
if list := d.Recv.List; len(list) > 0 {
|
if list := d.Recv.List; len(list) > 0 {
|
||||||
typ := list[0].Type
|
typ := list[0].Type
|
||||||
if ptr, _ := typ.(*ast.StarExpr); ptr != nil {
|
if ptr, _ := typ.(*ast.StarExpr); ptr != nil {
|
||||||
|
|
@ -307,7 +306,6 @@ func (check *checker) resolveFiles(files []*ast.File) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
objList = append(objList, obj)
|
objList = append(objList, obj)
|
||||||
objMap[obj] = declInfo{scope, nil, nil, d}
|
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.
|
// and collect it with the named base type.
|
||||||
if m != nil {
|
if m != nil {
|
||||||
check.objDecl(m, nil, true)
|
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)
|
named.methods = append(named.methods, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
delete(check.methods, obj.name) // we don't need them anymore
|
delete(check.methods, obj.name) // we don't need them anymore
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ var sources = []string{
|
||||||
type I interface{ m() }
|
type I interface{ m() }
|
||||||
var _ = T{a: 1, b: 2, c: 3}
|
var _ = T{a: 1, b: 2, c: 3}
|
||||||
func (_ T) m() {}
|
func (_ T) m() {}
|
||||||
|
func (T) _() {}
|
||||||
var i I
|
var i I
|
||||||
var _ = i.m
|
var _ = i.m
|
||||||
func _(s []int) { for i, x := range s {} }
|
func _(s []int) { for i, x := range s {} }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue