Skip to content

Commit 251496e

Browse files
committed
show file name in ERROR: unknown stmt/expr type errors
1 parent e72f6d2 commit 251496e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

nargs.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Flags struct {
2929

3030
type unusedVisitor struct {
3131
fileSet *token.FileSet
32+
currentFile *token.File
3233
resultsSet map[string]struct{}
3334
includeNamedReturns bool
3435
includeReceivers bool
@@ -106,9 +107,11 @@ func (v *unusedVisitor) Visit(node ast.Node) ast.Visitor {
106107
}
107108
stmtList = v.handleFuncDecl(paramMap, funcDecl, stmtList)
108109
file = v.fileSet.File(funcDecl.Pos())
110+
v.currentFile = file
109111

110112
case *ast.File:
111113
file = v.fileSet.File(topLevelType.Pos())
114+
v.currentFile = file
112115
if topLevelType.Decls != nil {
113116
stmtList = v.handleDecls(paramMap, topLevelType.Decls, stmtList)
114117
}
@@ -244,7 +247,7 @@ func (v *unusedVisitor) handleStmts(paramMap map[string]bool, stmtList []ast.Stm
244247
// no-op
245248

246249
default:
247-
log.Printf("ERROR: unknown stmt type %T\n", s)
250+
log.Printf("ERROR: unknown stmt type %T in file %v\n", s, v.currentFile.Name())
248251
}
249252

250253
stmtList = stmtList[1:]
@@ -363,7 +366,7 @@ func (v *unusedVisitor) handleExprs(paramMap map[string]bool, exprList []ast.Exp
363366
// no op
364367

365368
default:
366-
log.Printf("ERROR: unknown expr type %T\n", e)
369+
log.Printf("ERROR: unknown expr type %T in file %v\n", e, v.currentFile.Name())
367370
}
368371
exprList = exprList[1:]
369372
}

0 commit comments

Comments
 (0)