Open 9382 opened 1 month ago
VMIFY Scoping problem.
that
There is a possible fix for this.
Possible fix #1:
Add a boolean reference in Repeat Statement AST named "hasUpvalue", set it to false if one of the condition variables only refers inside the Repeat loop or true by default; all of this can be done during parsing, and then add a check like this in the compiler.
if statement.hasUpvalue then
-- Handle the condition first, which means no local variable refers from body to condition, which is safe.
else
-- Handle the loop body first (this is where the fix should be applied).
end
before the code:
local conditionReg = self:compileExpression(statement.condition, funcDepth, 1)[1];
Possible fix #2:
Add a function in the compiler that safely traverses expressions, so that you can check if there is a local variable inside the Repeat loop that is being used in the condition.
If anyone is willing to fix this issue, I am willing to accept a PR, but I currently do not have time, to fix this myself due to personal reasons.
VMify will fail if there's a repeat until statement that references a local in the
until
condition that was first defined in therepeat
's bodyCode to reproduce:
The actual code that parses the repeat until (src/prometheus/parser.lua#L225-L233) is parsing the condition with the return's scope, which should be good, but for some reason something later is breaking because of this, and I have no idea what