1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
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
-- flags --
-min_go=go1.20
-- go.mod --
module example.com/rm
go 1.20
-- basic.go --
package rm
type Basic int
func (t Basic) Foo(x int) { //@codeaction("x", "x", "refactor.rewrite", 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
-- @basic/basic.go --
package rm
type Basic int
func (t Basic) Foo() { //@codeaction("x", "x", "refactor.rewrite", 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
-- missingrecv.go --
package rm
type Missing struct{}
var r2 int
func (Missing) M(a, b, c, r0 int) (r1 int) { //@codeaction("b", "b", "refactor.rewrite", 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", "b", "refactor.rewrite", 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
|