From a66ec0d18eba6b38fad25cc88c82f7532d689670 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 9 Feb 2022 10:52:49 +0800 Subject: fix a case nil coalesing used as update assignment. --- src/yuescript/yue_compiler.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 852a0f4..db225f6 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -60,7 +60,7 @@ using namespace parserlib; typedef std::list str_list; -const std::string_view version = "0.9.7"sv; +const std::string_view version = "0.9.8"sv; const std::string_view extension = "yue"sv; class YueCompilerImpl { @@ -2081,8 +2081,9 @@ private: rightExp->pipeExprs.dup(leftExp->pipeExprs); rightExp->opValues.dup(leftExp->opValues); rightExp->nilCoalesed.set(update->value); - transformNilCoalesedExp(rightExp, out, ExpUsage::Assignment, assignment->expList, true); - if (!defs.empty()) out.back().insert(0, defs + nll(x)); + transformNilCoalesedExp(rightExp, temp, ExpUsage::Assignment, assignment->expList, true); + if (!defs.empty()) temp.back().insert(0, defs + nll(x)); + out.push_back(join(temp)); return; } auto defs = getPredefine(assignment); @@ -2495,7 +2496,7 @@ private: assignment->expList.set(expList); assignment->action.set(assign); transformAssignment(assignment, temp); - return true; + return forAssignment; } return false; }; @@ -2552,8 +2553,9 @@ private: assign->values.push_back(exp->nilCoalesed); auto defs = getPredefine(assignment); if (!defs.empty()) temp.push_back(defs + nll(x)); - prepareValue(); - _buf << indent() << "if "sv << objVar << " == nil then"sv << nll(x); + transformExp(left, temp, ExpUsage::Closure); + _buf << indent() << "if "sv << temp.back() << " == nil then"sv << nll(x); + temp.pop_back(); temp.push_back(clearBuf()); } pushScope(); -- cgit v1.2.3-55-g6feb