File tree 3 files changed +21
-1
lines changed
gopls/internal/analysis/modernize
3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -179,7 +179,11 @@ func mapsloop(pass *analysis.Pass) {
179
179
180
180
if rng .Tok == token .DEFINE && rng .Key != nil && rng .Value != nil && len (rng .Body .List ) == 1 {
181
181
// Have: for k, v := range x { S }
182
- if assign , ok := rng .Body .List [0 ].(* ast.AssignStmt ); ok && len (assign .Lhs ) == 1 {
182
+ if assign , ok := rng .Body .List [0 ].(* ast.AssignStmt ); ok &&
183
+ assign .Tok == token .ASSIGN &&
184
+ len (assign .Lhs ) == 1 {
185
+ // Have: for k, v := range x { lhs = rhs }
186
+
183
187
if index , ok := assign .Lhs [0 ].(* ast.IndexExpr ); ok &&
184
188
equalSyntax (rng .Key , index .Index ) &&
185
189
equalSyntax (rng .Value , assign .Rhs [0 ]) {
Original file line number Diff line number Diff line change @@ -138,3 +138,11 @@ func nopeBodyNotASingleton(src map[int]string) {
138
138
println () // nope: other things in the loop body
139
139
}
140
140
}
141
+
142
+ // Regression test for https://github.com/golang/go/issues/70815#issuecomment-2581999787.
143
+ func nopeAssignmentHasIncrementOperator (src map [int ]int ) {
144
+ dst := make (map [int ]int )
145
+ for k , v := range src {
146
+ dst [k ] += v
147
+ }
148
+ }
Original file line number Diff line number Diff line change @@ -110,3 +110,11 @@ func nopeBodyNotASingleton(src map[int]string) {
110
110
println() // nope: other things in the loop body
111
111
}
112
112
}
113
+
114
+ // Regression test for https://github.com/golang/go/issues/70815#issuecomment-2581999787.
115
+ func nopeAssignmentHasIncrementOperator(src map[int]int) {
116
+ dst := make(map[int]int)
117
+ for k, v := range src {
118
+ dst[k] += v
119
+ }
120
+ }
You can’t perform that action at this time.
0 commit comments