Debian Codegraph @

gopls/internal/test/marker/testdata/codeaction/inline-lhs-var-method.txt

raw
1 We should not offer a code action to inline 'v' where it appears on the
2 left-hand side of an assignment: method with pointer receiver.
3
4 Regression test for issue #75200.
5
6 -- go.mod --
7 module example.com/a
8 go 1.18
9
10 -- c/c.go --
11 package c
12
13 import "fmt"
14
15 type V int
16
17 func (V) Method() { }
18
19 func (*V) PointerMethod() { }
20
21 func _() {
22 var v V = V(123)
23 v = V(13)
24 v.Method() //@codeaction("v", "refactor.inline.variable", result=inlineV)
25 v.PointerMethod() //@codeaction("v", "refactor.inline.variable", err="0 CodeActions of kind refactor.inline.variable")
26 (v).PointerMethod() //@codeaction("v", "refactor.inline.variable", err="0 CodeActions of kind refactor.inline.variable")
27 var vptr *V = &v
28 vptr.PointerMethod() //@codeaction("vptr", "refactor.inline.variable", result=inlintVptr)
29 (vptr).PointerMethod() //@codeaction("vptr", "refactor.inline.variable", result=inlintVptrpar)
30 fmt.Println(v, vptr)
31 }
32
33 -- @inlineV/c/c.go --
34 package c
35
36 import "fmt"
37
38 type V int
39
40 func (V) Method() { }
41
42 func (*V) PointerMethod() { }
43
44 func _() {
45 var v V = V(123)
46 v = V(13)
47 V(123).Method() //@codeaction("v", "refactor.inline.variable", result=inlineV)
48 v.PointerMethod() //@codeaction("v", "refactor.inline.variable", err="0 CodeActions of kind refactor.inline.variable")
49 (v).PointerMethod() //@codeaction("v", "refactor.inline.variable", err="0 CodeActions of kind refactor.inline.variable")
50 var vptr *V = &v
51 vptr.PointerMethod() //@codeaction("vptr", "refactor.inline.variable", result=inlintVptr)
52 (vptr).PointerMethod() //@codeaction("vptr", "refactor.inline.variable", result=inlintVptrpar)
53 fmt.Println(v, vptr)
54 }
55
56 -- @inlintVptr/c/c.go --
57 package c
58
59 import "fmt"
60
61 type V int
62
63 func (V) Method() { }
64
65 func (*V) PointerMethod() { }
66
67 func _() {
68 var v V = V(123)
69 v = V(13)
70 v.Method() //@codeaction("v", "refactor.inline.variable", result=inlineV)
71 v.PointerMethod() //@codeaction("v", "refactor.inline.variable", err="0 CodeActions of kind refactor.inline.variable")
72 (v).PointerMethod() //@codeaction("v", "refactor.inline.variable", err="0 CodeActions of kind refactor.inline.variable")
73 var vptr *V = &v
74 (&v).PointerMethod() //@codeaction("vptr", "refactor.inline.variable", result=inlintVptr)
75 (vptr).PointerMethod() //@codeaction("vptr", "refactor.inline.variable", result=inlintVptrpar)
76 fmt.Println(v, vptr)
77 }
78
79 -- @inlintVptrpar/c/c.go --
80 package c
81
82 import "fmt"
83
84 type V int
85
86 func (V) Method() { }
87
88 func (*V) PointerMethod() { }
89
90 func _() {
91 var v V = V(123)
92 v = V(13)
93 v.Method() //@codeaction("v", "refactor.inline.variable", result=inlineV)
94 v.PointerMethod() //@codeaction("v", "refactor.inline.variable", err="0 CodeActions of kind refactor.inline.variable")
95 (v).PointerMethod() //@codeaction("v", "refactor.inline.variable", err="0 CodeActions of kind refactor.inline.variable")
96 var vptr *V = &v
97 vptr.PointerMethod() //@codeaction("vptr", "refactor.inline.variable", result=inlintVptr)
98 (&v).PointerMethod() //@codeaction("vptr", "refactor.inline.variable", result=inlintVptrpar)
99 fmt.Println(v, vptr)
100 }
101