From 70b30c67a74e9156b243e588423e8ef4e62dcd19 Mon Sep 17 00:00:00 2001 From: esimonov Date: Sat, 20 Feb 2021 22:58:28 +0200 Subject: [PATCH] Handle KeyValueExpr properly --- pkg/analyzer/analyzer.go | 8 ++------ testdata/testdata.go | 13 ++++++++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/analyzer/analyzer.go b/pkg/analyzer/analyzer.go index 36bb8d1..97a5664 100644 --- a/pkg/analyzer/analyzer.go +++ b/pkg/analyzer/analyzer.go @@ -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 { diff --git a/testdata/testdata.go b/testdata/testdata.go index 8e51325..8fcece1 100644 --- a/testdata/testdata.go +++ b/testdata/testdata.go @@ -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 @@ -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 {