Debian Codegraph @

gopls/internal/test/marker/testdata/codeaction/moveparam_issue70599.txt

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