fix: close upvalues before fiber completion and add closure tests
Move upvalue closing logic from the else branch to before the fiber completion check to ensure upvalues are properly closed when a fiber finishes. Add test cases for closure behavior across fiber yields and for Fiber.create argument type validation.
This commit is contained in:
+8
-10
@@ -883,14 +883,20 @@ static bool runInterpreter(WrenVM* vm)
|
||||
Value result = POP();
|
||||
fiber->numFrames--;
|
||||
|
||||
// Close any upvalues still in scope.
|
||||
Value* firstValue = &fiber->stack[frame->stackStart];
|
||||
while (fiber->openUpvalues != NULL &&
|
||||
fiber->openUpvalues->value >= firstValue)
|
||||
{
|
||||
closeUpvalue(fiber);
|
||||
}
|
||||
|
||||
// If the fiber is complete, end it.
|
||||
if (fiber->numFrames == 0)
|
||||
{
|
||||
// If this is the main fiber, we're done.
|
||||
if (fiber->caller == NULL) return true;
|
||||
|
||||
// TODO: Do we need to close upvalues here?
|
||||
|
||||
// We have a calling fiber to resume.
|
||||
fiber = fiber->caller;
|
||||
|
||||
@@ -899,14 +905,6 @@ static bool runInterpreter(WrenVM* vm)
|
||||
}
|
||||
else
|
||||
{
|
||||
// Close any upvalues still in scope.
|
||||
Value* firstValue = &fiber->stack[frame->stackStart];
|
||||
while (fiber->openUpvalues != NULL &&
|
||||
fiber->openUpvalues->value >= firstValue)
|
||||
{
|
||||
closeUpvalue(fiber);
|
||||
}
|
||||
|
||||
// Store the result of the block in the first slot, which is where the
|
||||
// caller expects it.
|
||||
fiber->stack[frame->stackStart] = result;
|
||||
|
||||
Reference in New Issue
Block a user