Skip to content

x/tools/gopls: ChangeSignature: crash in in inliner (likely due to ill-formed variadic call) #73187

Open
@adonovan

Description

@adonovan
#!stacks
"panicdottypeI" && "inline.(*state).inlineCall:+370"

Issue created by stacks.

				// simplify decl: func(T...) -> func([]T)
				lastParamField := last(calleeDecl.Type.Params.List)
				lastParamField.Type = &ast.ArrayType{
					Elt: lastParamField.Type.(*ast.Ellipsis).Elt,   <---- panicdottypeI
				}

The fix is to do something like what gopls does in gopls/internal/golang/inline.go, but in the inline package itself so that all callers (e.g. ChangeSignature) benefit:

	// The inliner assumes that input is well-typed,
	// but that is frequently not the case within gopls.
	// Until we are able to harden the inliner,
	// report panics as errors to avoid crashing the server.
	bad := func(p *cache.Package) bool { return len(p.ParseErrors())+len(p.TypeErrors()) > 0 }
	if bad(calleePkg) || bad(callerPkg) {
		defer func() {
			if x := recover(); x != nil {
				err = fmt.Errorf("inlining failed (%q), likely because inputs were ill-typed", x)
			}
		}()
	}

This stack nlN-6w was reported by telemetry:

golang.org/x/tools/gopls@v0.18.1 go1.23.5 darwin/arm64 vscode (2)

Activity

added
goplsIssues related to the Go language server, gopls.
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
ToolsThis label describes issues relating to any tools in the x/tools repository.
on Apr 6, 2025
added this to the gopls/v0.19.0 milestone on Apr 6, 2025
added
BugReportIssues describing a possible bug in the Go implementation.
on Apr 6, 2025
adonovan

adonovan commented on Apr 21, 2025

@adonovan
MemberAuthor

I'm not sure what kind of input could trigger this: we have sig.Variadic(), meaning the callee's parameter list is known to end in ...T, yet the syntax for the callee's FuncType.Params doesn't end in ast.Ellipsis. Even in ill-typed code, one would expect the type-checker's Variadic flag to be consistent with the FuncType.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/telemetry-wins

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @adonovan@gopherbot@findleyr@gabyhelp

        Issue actions

          x/tools/gopls: ChangeSignature: crash in in inliner (likely due to ill-formed variadic call) · Issue #73187 · golang/go