Skip to content
This repository has been archived by the owner on Jul 31, 2022. It is now read-only.

Commit

Permalink
Fix issue #6
Browse files Browse the repository at this point in the history
  • Loading branch information
esimonov committed Feb 6, 2021
1 parent f5a7f3d commit 0ee1452
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (nom namedOccurrenceMap) checkStatement(stmt ast.Stmt, ifPos token.Pos) {
nom.checkExpression(r, token.NoPos)
}
case *ast.SendStmt:
nom.checkExpression(v.Chan, token.NoPos)
nom.checkExpression(v.Value, token.NoPos)
case *ast.SwitchStmt:
nom.checkExpression(v.Tag, token.NoPos)
Expand Down Expand Up @@ -177,6 +178,7 @@ func (nom namedOccurrenceMap) checkExpression(candidate ast.Expr, ifPos token.Po
switch v := candidate.(type) {
case *ast.BinaryExpr:
nom.checkExpression(v.X, ifPos)
nom.checkExpression(v.Y, ifPos)
case *ast.CallExpr:
for _, arg := range v.Args {
nom.checkExpression(arg, ifPos)
Expand Down
21 changes: 20 additions & 1 deletion testdata/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,16 @@ func notUsed_ReturnStmt_OK() interface{} {
return v
}

func notUsed_SendStmt_OK() {
func notUsed_SendStmt_Chan_OK(v interface{}) {
ch := make(chan interface{})

if ch == nil {
return
}
ch <- v
}

func notUsed_SendStmt_Value_OK() {
v := getValue()
if v != nil {
noOp1(v)
Expand Down Expand Up @@ -472,3 +481,13 @@ func notUsed_TypeAssertion_OK() {
noOp2(w)
}
}

func notUsed_BinaryExprInAssign_OK() {
v1 := "v1"

_ = "v2" + v1

if false {
noOp1(v1)
}
}

0 comments on commit 0ee1452

Please sign in to comment.