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

Commit

Permalink
Process Idents in CompositeLit (issue #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
esimonov committed Mar 12, 2021
1 parent 70b30c6 commit c1bcdfa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,13 @@ func (nom namedOccurrenceMap) checkExpression(candidate ast.Expr, ifPos token.Po
}
case *ast.CompositeLit:
for _, el := range v.Elts {
kv, ok := el.(*ast.KeyValueExpr)
if !ok {
continue
switch v := el.(type) {
case *ast.Ident:
nom.checkExpression(v, ifPos)
case *ast.KeyValueExpr:
nom.checkExpression(v.Key, ifPos)
nom.checkExpression(v.Value, ifPos)
}
nom.checkExpression(kv.Key, ifPos)
nom.checkExpression(kv.Value, ifPos)
}
case *ast.FuncLit:
for _, el := range v.Body.List {
Expand Down
8 changes: 8 additions & 0 deletions testdata/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ func notUsed_CompositeLiteral_Struct_OK() dummyType {
}
}

func notUsed_CompositeLiteral_Array_OK() []interface{} {
v := getValue()
if v == nil {
return nil
}
return []interface{}{v}
}

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

0 comments on commit c1bcdfa

Please sign in to comment.