@@ -133,13 +133,13 @@ func (c *Checker) ProgramSSA(prog *ssa.Program) {
133
133
c .prog = prog
134
134
}
135
135
136
- // Algo supplies Checker with the call graph construction algorithm.
137
- func (c * Checker ) Algo (algo string ) {
136
+ // CallgraphAlgorithm supplies Checker with the call graph construction algorithm.
137
+ func (c * Checker ) CallgraphAlgorithm (algo string ) {
138
138
c .algo = algo
139
139
}
140
140
141
- // Algo supplies Checker with the exported setting.
142
- func (c * Checker ) Exported (exported bool ) {
141
+ // CheckExportedFuncs sets whether to inspect exported functions
142
+ func (c * Checker ) CheckExportedFuncs (exported bool ) {
143
143
c .exported = exported
144
144
}
145
145
@@ -255,6 +255,16 @@ func (c *Checker) addIssue(fn *ssa.Function, pos token.Pos, format string, args
255
255
})
256
256
}
257
257
258
+ // constantValueToString returns string representation for constant value
259
+ func constantValueToString (val constant.Value ) string {
260
+ valStr := "nil" // an untyped nil is a nil constant.Value
261
+ if val != nil {
262
+ valStr = val .String ()
263
+ }
264
+
265
+ return valStr
266
+ }
267
+
258
268
// checkFunc checks a single function for unused parameters.
259
269
func (c * Checker ) checkFunc (fn * ssa.Function , pkgInfo * loader.PackageInfo ) {
260
270
c .debug ("func %s\n " , fn .RelString (fn .Package ().Pkg ))
@@ -310,10 +320,7 @@ func (c *Checker) checkFunc(fn *ssa.Function, pkgInfo *loader.PackageInfo) {
310
320
// just one non-nil return (too many false positives)
311
321
continue
312
322
}
313
- valStr := "nil" // an untyped nil is a nil constant.Value
314
- if val != nil {
315
- valStr = val .String ()
316
- }
323
+ valStr := constantValueToString (val )
317
324
if calledInReturn (inboundCalls ) {
318
325
continue
319
326
}
@@ -497,10 +504,11 @@ func (c *Checker) alwaysReceivedConst(in []*callgraph.Edge, par *ssa.Parameter,
497
504
seenOrig = ""
498
505
}
499
506
}
500
- if seenOrig != "" && seenOrig != seen .String () {
507
+ seenStr := constantValueToString (seen )
508
+ if seenOrig != "" && seenOrig != seenStr {
501
509
return fmt .Sprintf ("%s (%v)" , seenOrig , seen )
502
510
}
503
- return seen . String ()
511
+ return seenStr
504
512
}
505
513
506
514
// anyRealUse reports whether a parameter has any relevant use within its
0 commit comments