Skip to content

Commit 1e95f12

Browse files
committed
fix detection inside range loop
1 parent 6f0aa84 commit 1e95f12

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pkg/analyzer/analyzer.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,10 @@ func stmtSetsAllowImplicitForObj(stmt ast.Stmt, obj types.Object, pass *analysis
461461
if handleForAllowImplicit(stmtNode, obj, pass) {
462462
return true
463463
}
464+
case *ast.RangeStmt:
465+
if handleRangeAllowImplicit(stmtNode, obj, pass) {
466+
return true
467+
}
464468
case *ast.SwitchStmt:
465469
if handleSwitchAllowImplicit(stmtNode, obj, pass) {
466470
return true
@@ -647,3 +651,19 @@ func handleSwitchAllowImplicit(
647651

648652
return false
649653
}
654+
655+
// handleRangeAllowImplicit scans a range statement's body for assignments or initializations
656+
// that set AllowImplicit for the given object. Mirrors ForStmt handling semantics.
657+
func handleRangeAllowImplicit(stmtNode *ast.RangeStmt, obj types.Object, pass *analysis.Pass) bool {
658+
if stmtNode == nil || stmtNode.Body == nil {
659+
return false
660+
}
661+
662+
for _, st := range stmtNode.Body.List {
663+
if stmtSetsAllowImplicitForObj(st, obj, pass) {
664+
return true
665+
}
666+
}
667+
668+
return false
669+
}

pkg/analyzer/testdata/src/common/range_loops.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func rangeLoops() {
1616
for range []int{1, 2, 3} {
1717
opts.AllowImplicit = true
1818
}
19-
db.BeginTransaction(ctx, arangodb.TransactionCollections{}, opts) // want "missing AllowImplicit option"
19+
db.BeginTransaction(ctx, arangodb.TransactionCollections{}, opts)
2020

2121
// Control: no mutation in range.
2222
opts2 := &arangodb.BeginTransactionOptions{}

0 commit comments

Comments
 (0)