Skip to content

Commit eb46939

Browse files
committed
gopls/internal/test/marker: add reproducers for moveparam bug bash bugs
Add a marker test that reproduces bugs encountered during bug bash of parameter movement refactoring. Subsequent CLs will fix these bugs. For golang/go#70599 Change-Id: Ieb52c1c02f11fa22bc043d7793509914d76d27ca Reviewed-on: https://go-review.googlesource.com/c/tools/+/632115 Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 4296223 commit eb46939

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
This test reproduces various bugs encountered while bug-bashing on the movement
2+
refactoring.
3+
4+
TODO(rfindley): fix these bugs.
5+
6+
-- go.mod --
7+
module example.com
8+
9+
go 1.21
10+
11+
-- unnecessaryconversion.go --
12+
package a
13+
14+
// We should not add unnecessary conversions to concrete arguments to concrete
15+
// parameters when the parameter use is in assignment context.
16+
17+
type Hash [32]byte
18+
19+
func Cache(key [32]byte, value any) { //@codeaction("key", "refactor.rewrite.moveParamRight", result=conversion)
20+
// Not implemented.
21+
}
22+
23+
func _() {
24+
var k Hash
25+
Cache(k, 0)
26+
Cache(Hash{}, 1)
27+
Cache([32]byte{}, 2)
28+
}
29+
30+
-- @conversion/unnecessaryconversion.go --
31+
package a
32+
33+
// We should not add unnecessary conversions to concrete arguments to concrete
34+
// parameters when the parameter use is in assignment context.
35+
36+
type Hash [32]byte
37+
38+
func Cache(value any, key [32]byte) { //@codeaction("key", "refactor.rewrite.moveParamRight", result=conversion)
39+
// Not implemented.
40+
}
41+
42+
func _() {
43+
var k Hash
44+
Cache(0, [32]byte(k))
45+
Cache(1, [32]byte(Hash{}))
46+
Cache(2, [32]byte{})
47+
}
48+
-- shortvardecl.go --
49+
package a
50+
51+
func Short(x, y int) (int, int) { //@codeaction("x", "refactor.rewrite.moveParamRight", result=short)
52+
return x, y
53+
}
54+
55+
func _() {
56+
x, y := Short(0, 1)
57+
_, _ = x, y
58+
}
59+
60+
func _() {
61+
var x, y int
62+
x, y = Short(0, 1)
63+
_, _ = x, y
64+
}
65+
66+
func _() {
67+
_, _ = Short(0, 1)
68+
}
69+
-- @short/shortvardecl.go --
70+
package a
71+
72+
func Short(y, x int) (int, int) { //@codeaction("x", "refactor.rewrite.moveParamRight", result=short)
73+
return x, y
74+
}
75+
76+
func _() {
77+
var x, y int
78+
x, y = Short(1, 0)
79+
_, _ = x, y
80+
}
81+
82+
func _() {
83+
var x, y int
84+
x, y = Short(1, 0)
85+
_, _ = x, y
86+
}
87+
88+
func _() {
89+
_, _ = Short(1, 0)
90+
}
91+
-- variadic.go --
92+
package a
93+
94+
// We should not offer movement involving variadic parameters if it is not well
95+
// supported.
96+
97+
func Variadic(x int, y ...string) { //@codeaction("x", "refactor.rewrite.moveParamRight", err="type checking rewritten package")
98+
}
99+
100+
func _() {
101+
Variadic(1, "a", "b")
102+
}

0 commit comments

Comments
 (0)