Skip to content

Commit 7efe9a8

Browse files
adonovangopherbot
authored andcommitted
gopls/internal/analysis/modernize: rangeint: fix yet another bug
ASSIGN and DEFINE are not the only kinds of AssignStmt. + test Change-Id: I81b5122b0ac0db9be5178b6685c00212f3c4c469 Reviewed-on: https://go-review.googlesource.com/c/tools/+/660695 Reviewed-by: Jonathan Amsterdam <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Alan Donovan <[email protected]>
1 parent 30641f5 commit 7efe9a8

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

gopls/internal/analysis/modernize/rangeint.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ func isScalarLvalue(info *types.Info, curId cursor.Cursor) bool {
263263
switch ek {
264264
case edge.AssignStmt_Lhs:
265265
assign := cur.Parent().Node().(*ast.AssignStmt)
266-
if assign.Tok == token.ASSIGN {
267-
return true // i = j
266+
if assign.Tok != token.DEFINE {
267+
return true // i = j or i += j
268268
}
269269
id := curId.Node().(*ast.Ident)
270270
if v, ok := info.Defs[id]; ok && v.Pos() != id.Pos() {

gopls/internal/analysis/modernize/testdata/src/rangeint/rangeint.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ func _(i int, s struct{ i int }, slice []int) {
132132
s = s[1:]
133133
}
134134
}
135+
for i := 0; i < len(slice); i++ { // nope: i is incremented within loop
136+
i += 1
137+
}
135138
}
136139

137140
var Global int

gopls/internal/analysis/modernize/testdata/src/rangeint/rangeint.go.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ func _(i int, s struct{ i int }, slice []int) {
132132
s = s[1:]
133133
}
134134
}
135+
for i := 0; i < len(slice); i++ { // nope: i is incremented within loop
136+
i += 1
137+
}
135138
}
136139

137140
var Global int

0 commit comments

Comments
 (0)