Skip to content

Commit cb89abc

Browse files
committed
Merge branch 'fix/issue-152-repository-ttl-maxsize' into 'main'
fix(compiler): exclude for-each item/index vars from loop body pre-unbind See merge request arolang/aro!170
2 parents cdcf3a0 + c14ef40 commit cb89abc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Sources/AROCompiler/LLVMC/LLVMCodeGenerator.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,9 +1190,14 @@ public final class LLVMCodeGenerator {
11901190

11911191
// Unbind all variables that will be bound in the loop body
11921192
// This simulates the child context behavior of the interpreter,
1193-
// allowing variables to be rebound on each iteration
1193+
// allowing variables to be rebound on each iteration.
1194+
// Exclude the item variable and index variable — they are already
1195+
// managed by the dedicated unbind+rebind code above, mirroring
1196+
// the same exclusion in generateRangeLoop (line: varName != loop.variable).
1197+
var managedByLoop = Set([loop.itemVariable])
1198+
if let indexVar = loop.indexVariable { managedByLoop.insert(indexVar) }
11941199
let bodyVariables = collectBoundVariables(from: loop.body)
1195-
for varName in bodyVariables {
1200+
for varName in bodyVariables where !managedByLoop.contains(varName) {
11961201
let varNameConst = ctx.stringConstant(varName)
11971202
_ = ctx.module.insertCall(
11981203
externals.variableUnbind,

Sources/ARORuntime/Bridge/RuntimeBridge.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,13 @@ private func convertToSendable(_ value: Any) -> any Sendable {
14171417
// This case should not be reached on macOS (CFBoolean is NSNumber)
14181418
// But keep it for other platforms
14191419
return bool
1420+
case let sendableDict as [String: any Sendable]:
1421+
// Already the correct type — recurse to ensure nested values are also clean
1422+
var result: [String: any Sendable] = [:]
1423+
for (k, v) in sendableDict {
1424+
result[k] = convertToSendable(v)
1425+
}
1426+
return result
14201427
case let dict as [String: Any]:
14211428
var result: [String: any Sendable] = [:]
14221429
for (k, v) in dict {

0 commit comments

Comments
 (0)