From e02321107277a63e7dcb12ab163c9942ac101b87 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Mon, 26 Jan 2026 17:45:26 +0800 Subject: Updated tests. --- src/yuescript/yue_compiler.cpp | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index d20b94b..c5e4a78 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -78,7 +78,7 @@ static std::unordered_set Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.32.4"sv; +const std::string_view version = "0.32.5"sv; const std::string_view extension = "yue"sv; class CompileError : public std::logic_error { @@ -10226,7 +10226,7 @@ private: } else if (auto expList = expListFrom(statement)) { if (auto value = singleValueFrom(expList)) { clsDecl = value->get_by_path(); - } + } } if (clsDecl) { auto variable = clsDecl->name.as(); @@ -10244,10 +10244,18 @@ private: } _withVars.push(withVar); std::string breakWithVar; + bool extraBreakVar = false; if (assignList || returnValue) { - auto breakLoopType = getBreakLoopType(with->body, withVar); - if (hasBreakWithValue(breakLoopType)) { - breakWithVar = withVar; + if (assignList) { + breakWithVar = singleVariableFrom(assignList, AccessType::None); + } + if (breakWithVar.empty()) { + breakWithVar = getUnusedName("_val_"sv); + extraBreakVar = true; + } + auto breakLoopType = getBreakLoopType(with->body, breakWithVar); + if (!hasBreakWithValue(breakLoopType)) { + breakWithVar.clear(); } } if (with->eop) { @@ -10328,17 +10336,19 @@ private: } _withVars.pop(); if (assignList) { - auto assignment = x->new_ptr(); - assignment->expList.set(assignList); - auto assign = x->new_ptr(); - assign->values.push_back(toAst(withVar, x)); - assignment->action.set(assign); - transformAssignment(assignment, temp); + if (breakWithVar.empty() || extraBreakVar) { + auto assignment = x->new_ptr(); + assignment->expList.set(assignList); + auto assign = x->new_ptr(); + assign->values.push_back(toAst(breakWithVar.empty() ? withVar : breakWithVar, x)); + assignment->action.set(assign); + transformAssignment(assignment, temp); + } } if (returnValue) { auto last = lastStatementFrom(with->body); if (last && !last->content.is()) { - temp.push_back(indent() + "return "s + withVar + nl(with)); + temp.push_back(indent() + "return "s + (breakWithVar.empty() ? withVar : breakWithVar) + nl(with)); } } if (extraScope) { -- cgit v1.2.3-55-g6feb