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

Commit

Permalink
Handle KeyValueExpr properly
Browse files Browse the repository at this point in the history
  • Loading branch information
esimonov committed Feb 20, 2021
1 parent 67b6923 commit 70b30c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
8 changes: 2 additions & 6 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,8 @@ func (nom namedOccurrenceMap) checkExpression(candidate ast.Expr, ifPos token.Po
if !ok {
continue
}
if ident, ok := kv.Key.(*ast.Ident); ok {
nom.checkExpression(ident, ifPos)
}
if ident, ok := kv.Value.(*ast.Ident); ok {
nom.checkExpression(ident, ifPos)
}
nom.checkExpression(kv.Key, ifPos)
nom.checkExpression(kv.Value, ifPos)
}
case *ast.FuncLit:
for _, el := range v.Body.List {
Expand Down
13 changes: 12 additions & 1 deletion testdata/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func notUsed_SwitchStmt_Body_Assignment_OK() {
}
}

func notUsed_CompositeLiteral_OK() map[int]struct{} {
func notUsed_CompositeLiteral_Map_OK() map[int]struct{} {
a := 0
if a != 0 {
return nil
Expand All @@ -255,6 +255,17 @@ func notUsed_CompositeLiteral_OK() map[int]struct{} {
return map[int]struct{}{a: b}
}

func notUsed_CompositeLiteral_Struct_OK() dummyType {
d := getDummy()
if d.interf == 0 {
return d
}

return dummyType{
interf: getValue(d),
}
}

func notUsed_MultipleAssignments_OK() interface{} {
a, b := getTwoValues()
if a != nil {
Expand Down

0 comments on commit 70b30c6

Please sign in to comment.