Skip to content
Permalink
Browse files

fix up another false negative in testdata

In the go/ast search, look for just "_ = par", and not any mention of a
parameter like "par = someVal".
  • Loading branch information...
mvdan committed Feb 9, 2019
1 parent 229ad68 commit fbb59629db34a0f69275bc336cc8c3a4dd9fbe5d
Showing with 11 additions and 3 deletions.
  1. +9 −2 check/check.go
  2. +2 −1 testdata/scripts/stubs.txt
@@ -706,8 +706,15 @@ func (c *Checker) anyRealUse(par *ssa.Parameter, pos int, pkg *packages.Package)
if any {
return false
}
if id, ok := node.(*ast.Ident); ok {
obj := pkg.TypesInfo.Uses[id]
asgn, ok := node.(*ast.AssignStmt)
if !ok || asgn.Tok != token.ASSIGN || len(asgn.Lhs) != 1 || len(asgn.Rhs) != 1 {
return true
}
if left, ok := asgn.Lhs[0].(*ast.Ident); !ok || left.Name != "_" {
return true
}
if right, ok := asgn.Rhs[0].(*ast.Ident); ok {
obj := pkg.TypesInfo.Uses[right]
if obj != nil && obj.Pos() == par.Pos() {
any = true
}
@@ -10,6 +10,7 @@ foo.go:13:42: nonPanicImpl - f is unused
foo.go:30:43: nonPanicImpl2 - f is unused
foo.go:49:19: nonConstImpl - f is unused
foo.go:49:31: nonConstImpl - s is unused
foo.go:53:28: oneOverwritten - i is unused
-- foo.go --
package foo

@@ -64,7 +65,7 @@ func nonConstImpl(f fooError, s string) error { return iface.(error) }
func logImpl(f int) { log.Print("not implemented") }

func oneOverwritten(a int, i uint8) (int, uint8) {
i = 3 // TODO: skip this as a real use, without breaking "_ = i"
i = 3
a += 1
return a, i
}

0 comments on commit fbb5962

Please sign in to comment.
You can’t perform that action at this time.