Skip to content

Commit

Permalink
Merge pull request #9 from karamaru-alpha/fix/karamaru/panic
Browse files Browse the repository at this point in the history
fix: panic when rangeStmt value's type is not *ast.Ident
  • Loading branch information
karamaru-alpha committed Mar 22, 2024
2 parents 4ee136b + 57b8534 commit e45640c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion copyloopvar.go
Expand Up @@ -52,7 +52,9 @@ func checkRangeStmt(pass *analysis.Pass, rangeStmt *ast.RangeStmt) {
}
var value *ast.Ident
if rangeStmt.Value != nil {
value = rangeStmt.Value.(*ast.Ident)
if value, ok = rangeStmt.Value.(*ast.Ident); !ok {
return
}
}
for _, stmt := range rangeStmt.Body.List {
assignStmt, ok := stmt.(*ast.AssignStmt)
Expand Down
7 changes: 7 additions & 0 deletions testdata/src/basic/main.go
Expand Up @@ -20,4 +20,11 @@ func main() {
c, d := 1, j // want `The copy of the 'for' variable "j" can be deleted \(Go 1\.22\+\)`
_, _, _, _, _, _, _, _ = i, _i, j, _j, a, b, c, d
}

var t struct {
Bool bool
}
for _, t.Bool = range []bool{true, false} {
_ = t
}
}
7 changes: 7 additions & 0 deletions testdata/src/ignorealias/main.go
Expand Up @@ -20,4 +20,11 @@ func main() {
c, d := 1, j
_, _, _, _, _, _, _, _ = i, _i, j, _j, a, b, c, d
}

var t struct {
Bool bool
}
for _, t.Bool = range []bool{true, false} {
_ = t
}
}

0 comments on commit e45640c

Please sign in to comment.