This test exercises the refactoring to remove unused parameters.
See removeparam_resolve.txt for same test with resolve support.
-- go.mod --
module unused.mod
go 1.18
-- a/a.go --
package a
func A(x, unused int) int { //@codeaction("unused", "refactor.rewrite.removeUnusedParam", result=a)
return x
}
-- @a/a/a.go --
package a
func A(x int) int { //@codeaction("unused", "refactor.rewrite.removeUnusedParam", result=a)
return x
}
-- a/a2.go --
package a
func _() {
A(1, 2)
}
-- a/a_test.go --
package a
func _() {
A(1, 2)
}
-- a/a_x_test.go --
package a_test
import "unused.mod/a"
func _() {
a.A(1, 2)
}
-- b/b.go --
package b
import "unused.mod/a"
func f() int {
return 1
}
func g() int {
return 2
}
func _() {
a.A(f(), 1)
}
-- @a/a/a2.go --
package a
func _() {
A(1)
}
-- @a/a/a_test.go --
package a
func _() {
A(1)
}
-- @a/a/a_x_test.go --
package a_test
import "unused.mod/a"
func _() {
a.A(1)
}
-- @a/b/b.go --
package b
import "unused.mod/a"
func f() int {
return 1
}
func g() int {
return 2
}
func _() {
a.A(f())
}
-- field/field.go --
package field
func Field(x int, field int) { //@codeaction("int", "refactor.rewrite.removeUnusedParam", result=field)
}
func _() {
Field(1, 2)
}
-- @field/field/field.go --
package field
func Field(field int) { //@codeaction("int", "refactor.rewrite.removeUnusedParam", result=field)
}
func _() {
Field(2)
}
-- ellipsis/ellipsis.go --
package ellipsis
func Ellipsis(...any) { //@codeaction("any", "refactor.rewrite.removeUnusedParam", result=ellipsis)
}
func _() {
// TODO(rfindley): investigate the broken formatting resulting from these inlinings.
Ellipsis()
Ellipsis(1)
Ellipsis(1, 2)
Ellipsis(1, f(), g())
Ellipsis(h())
Ellipsis(i()...)
}
func f() int
func g() int
func h() (int, int)
func i() []any
-- @ellipsis/ellipsis/ellipsis.go --
package ellipsis
func Ellipsis() { //@codeaction("any", "refactor.rewrite.removeUnusedParam", result=ellipsis)
}
func _() {
// TODO(rfindley): investigate the broken formatting resulting from these inlinings.
Ellipsis()
Ellipsis()
Ellipsis()
var _ []any = []any{1, f(), g()}
Ellipsis()
func(_ ...any) {
Ellipsis()
}(h())
var _ []any = i()
Ellipsis()
}
func f() int
func g() int
func h() (int, int)
func i() []any
-- ellipsis2/ellipsis2.go --
package ellipsis2
func Ellipsis2(_, _ int, rest ...int) { //@codeaction("_", "refactor.rewrite.removeUnusedParam", result=ellipsis2)
}
func _() {
Ellipsis2(1,2,3)
Ellipsis2(h())
Ellipsis2(1,2, []int{3, 4}...)
}
func h() (int, int)
-- @ellipsis2/ellipsis2/ellipsis2.go --
package ellipsis2
func Ellipsis2(_ int, rest ...int) { //@codeaction("_", "refactor.rewrite.removeUnusedParam", result=ellipsis2)
}
func _() {
Ellipsis2(2, 3)
func(_, blank0 int, rest ...int) {
Ellipsis2(blank0, rest...)
}(h())
Ellipsis2(2, []int{3, 4}...)
}
func h() (int, int)
-- overlapping/overlapping.go --
package overlapping
func Overlapping(i int) int { //@codeaction(re"(i) int", "refactor.rewrite.removeUnusedParam", err=re"overlapping")
return 0
}
func _() {
x := Overlapping(Overlapping(0))
_ = x
}
-- effects/effects.go --
package effects
func effects(x, y int) int { //@ diag("y", re"unused"), codeaction("y", "refactor.rewrite.removeUnusedParam", result=effects)
return x
}
func f() int
func g() int
func _() {
effects(f(), g())
effects(f(), g())
}
-- @effects/effects/effects.go --
package effects
func effects(x int) int { //@ diag("y", re"unused"), codeaction("y", "refactor.rewrite.removeUnusedParam", result=effects)
return x
}
func f() int
func g() int
func _() {
var x, _ int = f(), g()
effects(x)
{
var x, _ int = f(), g()
effects(x)
}
}
-- recursive/recursive.go --
package recursive
func Recursive(x int) int { //@codeaction("x", "refactor.rewrite.removeUnusedParam", result=recursive)
return Recursive(1)
}
-- @recursive/recursive/recursive.go --
package recursive
func Recursive() int { //@codeaction("x", "refactor.rewrite.removeUnusedParam", result=recursive)
return Recursive()
}