Skip to content

Commit b5bbf40

Browse files
committed
Process method receiver in function declaration
Fixes #95
1 parent b5e29b6 commit b5bbf40

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

pkg/ineffassign/ineffassign.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ func (bld *builder) Visit(n ast.Node) ast.Visitor {
9696
switch n := n.(type) {
9797
case *ast.FuncDecl:
9898
if n.Body != nil {
99-
bld.fun(n.Type, n.Body)
99+
bld.fun(n.Recv, n.Type, n.Body)
100100
}
101101
case *ast.FuncLit:
102-
bld.fun(n.Type, n.Body)
102+
bld.fun(nil, n.Type, n.Body)
103103
case *ast.IfStmt:
104104
bld.walk(n.Init)
105105
bld.walk(n.Cond)
@@ -362,7 +362,7 @@ func isZeroInitializer(x ast.Expr) bool {
362362
return false
363363
}
364364

365-
func (bld *builder) fun(typ *ast.FuncType, body *ast.BlockStmt) {
365+
func (bld *builder) fun(recv *ast.FieldList, typ *ast.FuncType, body *ast.BlockStmt) {
366366
for _, v := range bld.vars {
367367
v.fundept++
368368
}
@@ -372,6 +372,9 @@ func (bld *builder) fun(typ *ast.FuncType, body *ast.BlockStmt) {
372372
b := bld.block
373373
bld.newBlock()
374374
bld.roots = append(bld.roots, bld.block)
375+
if recv != nil {
376+
bld.walk(recv)
377+
}
375378
bld.walk(typ)
376379
bld.walk(body)
377380
bld.block = b

pkg/ineffassign/testdata/testdata.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,3 +758,12 @@ func f(mu *sync.Mutex) (n int, err error) {
758758
}
759759

760760
func g() (int, error) { return 0, nil }
761+
762+
type T struct{}
763+
764+
func (t T) _() {
765+
func() {
766+
t = T{}
767+
}()
768+
_ = t
769+
}

0 commit comments

Comments
 (0)