From f7b674213bd996016cb94c44ef22736a6cbdf6f3 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 14 Jul 2022 17:35:04 +0800 Subject: fix else clause issue in switch statement with table matching. --- src/yuescript/yue_compiler.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 21764fe..85aa6d4 100755 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -56,7 +56,7 @@ using namespace parserlib; typedef std::list str_list; -const std::string_view version = "0.13.5"sv; +const std::string_view version = "0.13.6"sv; const std::string_view extension = "yue"sv; class YueCompilerImpl { @@ -7169,7 +7169,7 @@ private: temp.push_back(indent() + "local "s + tabCheckVar + " = \"table\" == "s + globalVar("type", branch) + '(' + objVar + ')' + nll(branch)); } std::string matchVar; - bool lastBranch = branches.back() == branch_; + bool lastBranch = branches.back() == branch_ && !switchNode->lastBranch; if (!lastBranch) { matchVar = getUnusedName("_match_"); forceAddToScope(matchVar); @@ -7232,8 +7232,12 @@ private: } } if (switchNode->lastBranch) { - temp.push_back(indent() + "else"s + nll(switchNode->lastBranch)); - pushScope(); + if (!firstBranch) { + temp.push_back(indent() + "else"s + nll(switchNode->lastBranch)); + pushScope(); + } else { + addScope--; + } transform_plain_body(switchNode->lastBranch, temp, usage, assignList); popScope(); } -- cgit v1.2.3-55-g6feb