8000 Anonymous-function analysis panics on a variadic function literal that captures a pointer-typed variable · Issue #532 · uber-go/nilaway · GitHub
[go: up one dir, main page]

Skip to content

Anonymous-function analysis panics on a variadic function literal that captures a pointer-typed variable #532

Open

Description

@marin-rusu-idt

-experimental-anonymous-function panics on a variadic function literal that captures a pointer-typed variable.

Version: go.uber.org/nilaway v0.0.0-20260918162853-acb8859b9031, Go 1.27.2 (darwin/arm64), golang.org/x/tools v0.50.0.

Reproducer (module example.com/repro, package b):

package b

type App struct{ Home string }

func (a *App) Roots() []string {
	join := func(parts ...string) string { return a.Home + parts[0] }

	return []string{join("x")}
}
$ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0