You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Anonymous-function analysis panics on a variadic function literal that captures a pointer-typed variable #532
$ nilaway -experimental-anonymous-function -include-errors-in-files=/ ./...
b/b.go:1:1: error: INTERNAL ERROR(s):
nilaway_assertion_analyzer: nilaway_function_analyzer: INTERNAL PANIC from "nilaway_anonymous_func_analyzer": got *example.com/repro/b.App, want variadic parameter of slice or string type
(-include-errors-in-files=/ is only there so the diagnostic is not filtered, #533.)
A literal that captures only a string does not panic, so the trigger is a variadic literal that captures a variable NilAway tracks (here the *App receiver). This is a common idiom (h := func(parts ...string) string { ... receiver ... }).
Cause:createFakeFuncDecl (assertion/anonymousfunc/analyzer.go) appends the captured variables after the literal's own parameters but still passes sig.Variadic() to types.NewSignatureType. The last parameter is then a captured variable, not a slice, so NewSignatureType panics. Passing variadic=false for the fake signature when there are captured variables, or inserting them before the variadic parameter, would probably avoid it.
As with #531, the panic discards the package's other findings: a genuine nil dereference in the same package is no longer reported once the flag is on.
Activity