This test verifies that gopls can remove unused parameters from methods.
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
go 1.20
-- basic.go --
package rm
type Basic int
func (t Basic) Foo(x int) { //@codeaction("x", "refactor.rewrite.removeUnusedParam", result=basic)
}
func _(b Basic) {
b.Foo(1)
// TODO(rfindley): methodexprs should not get rewritten as methods.
Basic.Foo(1, 2)
}
-- basicuse/p.go --
package basicuse
import "example.com/rm"
func _() {
x := new(rm.Basic)
x.Foo(sideEffects())
rm.Basic.Foo(1,2)
}
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
type Basic int
func (t Basic) Foo() { //@codeaction("x", "refactor.rewrite.removeUnusedParam", result=basic)
}
func _(b Basic) {
b.Foo()
// TODO(rfindley): methodexprs should not get rewritten as methods.
Basic(1).Foo()
}
-- @basic/basicuse/p.go --
package basicuse
import "example.com/rm"
func _() {
x := new(rm.Basic)
var (
t rm.Basic = *x
_ int = sideEffects()
)
t.Foo()
rm.Basic(1).Foo()
}
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
type Missing struct{}
var r2 int
func (Missing) M(a, b, c, r0 int) (r1 int) { //@codeaction("b", "refactor.rewrite.removeUnusedParam", result=missingrecv)
return a + c
}
func _() {
m := &Missing{}
_ = m.M(1, 2, 3, 4)
}
-- missingrecvuse/p.go --
package missingrecvuse
import "example.com/rm"
func _() {
x := rm.Missing{}
x.M(1, sideEffects(), 3, 4)
}
func sideEffects() int
-- @missingrecv/missingrecv.go --
package rm
type Missing struct{}
var r2 int
func (Missing) M(a, c, r0 int) (r1 int) { //@codeaction("b", "refactor.rewrite.removeUnusedParam", result=missingrecv)
return a + c
}
func _() {
m := &Missing{}
_ = m.M(1, 3, 4)
}
-- @missingrecv/missingrecvuse/p.go --
package missingrecvuse
import "example.com/rm"
func _() {
x := rm.Missing{}
var _ int = sideEffects()
x.M(1, 3, 4)
}
func sideEffects() int