go icon indicating copy to clipboard operation
go copied to clipboard

x/tools/gopls: "inline: corrupted reference %v" bug in golang.RemoveUnusedParameter

Open adonovan opened this issue 1 year ago • 1 comments

#!stacks
"bug.Errorf" && "golang.inlineAllCalls:+98"

Issue created by stacks.

		// Sanity check.
		if obj := refpkg.TypesInfo().ObjectOf(name); obj == nil ||
			obj.Name() != origDecl.Name.Name ||
			obj.Pkg() == nil ||
			obj.Pkg().Path() != string(pkg.Metadata().PkgPath) {
			return nil, bug.Errorf("cannot inline: corrupted reference %v", ref)
		}

This stack u1wk7A was reported by telemetry:

golang.org/x/tools/[email protected] go1.22.2 darwin/arm64 vscode (1)

adonovan avatar Oct 15 '24 18:10 adonovan

The failing assertion checks that each reference to the function or method of interest is a call to to a symbol with the same name and package as the original function. But the References algorithm returns implicit matches by joining with the "implements" relation, and these matches may come from arbitrary packages. So I think the assertion is overly strict.

adonovan avatar Nov 10 '24 21:11 adonovan

Thanks, that was indeed it, and I was able to reproduce.

Fix incoming.

findleyr avatar Nov 15 '24 20:11 findleyr

Change https://go.dev/cl/628376 mentions this issue: gopls/internal/golang: don't try to inline dynamic calls

gopherbot avatar Nov 15 '24 20:11 gopherbot