From c65ead24430d0cb3b0af3f896df43827dbf7bbb2 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 11 Feb 2026 17:38:58 +0800 Subject: Fixed issues. --- spec/outputs/test/with_statement_spec.lua | 16 ++++++---------- spec/outputs/with.lua | 2 -- src/yuescript/yue_compiler.cpp | 9 +++++---- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/spec/outputs/test/with_statement_spec.lua b/spec/outputs/test/with_statement_spec.lua index e6f64e8..8031364 100644 --- a/spec/outputs/test/with_statement_spec.lua +++ b/spec/outputs/test/with_statement_spec.lua @@ -201,16 +201,12 @@ return describe("with statement", function() local result do local _with_0 = nil - do - local _accum_0 = { } - repeat - if _with_0 ~= nil then - result = _with_0.value - break - end - until true - result = _accum_0 - end + repeat + if _with_0 ~= nil then + result = _with_0.value + break + end + until true end return assert.same(result, nil) end) diff --git a/spec/outputs/with.lua b/spec/outputs/with.lua index ce0e495..a9126be 100644 --- a/spec/outputs/with.lua +++ b/spec/outputs/with.lua @@ -212,14 +212,12 @@ do local _val_0 while true do local _with_0 = tb - local _accum_0 = { } repeat if _with_0 ~= nil then _val_0 = 1 break end until true - _val_0 = _accum_0 break end a = _val_0 diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index bd52d33..caeee53 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -10391,6 +10391,10 @@ private: if (breakWithVar.empty()) { transformIf(ifNode, temp, ExpUsage::Common); } else { + if (extraBreakVar) { + addToScope(breakWithVar); + temp.push_back(indent() + "local "s + breakWithVar + nl(with)); + } auto simpleValue = x->new_ptr(); simpleValue->value.set(ifNode); auto exp = newExp(simpleValue, x); @@ -10404,10 +10408,7 @@ private: auto block = x->new_ptr(); block->statementOrComments.push_back(stmt); repeatNode->body.set(block); - auto sVal = x->new_ptr(); - sVal->value.set(repeatNode); - auto asmt = assignmentFrom(toAst(breakWithVar, x), newExp(sVal, x), x); - transformAssignment(asmt, temp); + transformRepeat(repeatNode, temp); } } else { bool transformed = false; -- cgit v1.2.3-55-g6feb