-
Notifications
You must be signed in to change notification settings - Fork 41
Description
In the following code, the expected output when running in standard Lua should be 50. However, when executed in the Lua-CSharp implementation, the actual output is 100.
local n = 0
while n < 100 do
n = n + 1
if n == 50 then break end
while false do
n = n + 7
break
end
end
print(n)
Expected Behavior
Output:
50
Actual Behavior (Lua-CSharp)
Output:
100
After reviewing the code, I believe there is an issue with how the compiler handles break statements. The break queue is maintained in the FunctionCompilationContext, and all scopes share a single queue. This causes a problem when compiling a nested while statement: while compiling the inner while, the break queue is processed in such a way that breaks belonging to the outer while loop are also resolved, leading to incorrect jump targets.
In fact, during additional testing with other examples, I found that this behavior can sometimes result in unintended infinite loops.