diff --git a/gopls/internal/golang/inline_all.go b/gopls/internal/golang/inline_all.go index 9c0aa4115d6..2ee4c5beb0a 100644 --- a/gopls/internal/golang/inline_all.go +++ b/gopls/internal/golang/inline_all.go @@ -152,11 +152,16 @@ func inlineAllCalls(ctx context.Context, logf func(string, ...any), snapshot *ca continue } + if typeutil.StaticCallee(refpkg.TypesInfo(), call) == nil { + continue // dynamic call + } + // 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) } diff --git a/gopls/internal/test/marker/testdata/codeaction/removeparam_method.txt b/gopls/internal/test/marker/testdata/codeaction/removeparam_method.txt index 614c4d3147f..b3b20523fee 100644 --- a/gopls/internal/test/marker/testdata/codeaction/removeparam_method.txt +++ b/gopls/internal/test/marker/testdata/codeaction/removeparam_method.txt @@ -4,6 +4,7 @@ Specifically, check 1. basic removal of unused parameters, when the receiver is named, locally and across package boundaries 2. handling of unnamed receivers +3. no panics related to references through interface satisfaction -- go.mod -- module example.com/rm @@ -37,6 +38,16 @@ func _() { func sideEffects() int +type Fooer interface { + Foo(int) +} + +// Dynamic calls aren't rewritten. +// Previously, this would cause a bug report or crash (golang/go#69896). +func _(f Fooer) { + f.Foo(1) +} + -- @basic/basic.go -- package rm @@ -66,6 +77,16 @@ func _() { } func sideEffects() int + +type Fooer interface { + Foo(int) +} + +// Dynamic calls aren't rewritten. +// Previously, this would cause a bug report or crash (golang/go#69896). +func _(f Fooer) { + f.Foo(1) +} -- missingrecv.go -- package rm