aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-07-14 17:35:04 +0800
committerLi Jin <dragon-fly@qq.com>2022-07-14 17:35:04 +0800
commitf7b674213bd996016cb94c44ef22736a6cbdf6f3 (patch)
treec130d624f8445813d0b3dfbbbac0d698bd2b0f66 /src
parent9c1d7bca08a88254ac33d7df16fc0a48f34912f4 (diff)
downloadyuescript-f7b674213bd996016cb94c44ef22736a6cbdf6f3.tar.gz
yuescript-f7b674213bd996016cb94c44ef22736a6cbdf6f3.tar.bz2
yuescript-f7b674213bd996016cb94c44ef22736a6cbdf6f3.zip
fix else clause issue in switch statement with table matching.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/yuescript/yue_compiler.cpp12
1 files changed, 8 insertions, 4 deletions
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;
56 56
57typedef std::list<std::string> str_list; 57typedef std::list<std::string> str_list;
58 58
59const std::string_view version = "0.13.5"sv; 59const std::string_view version = "0.13.6"sv;
60const std::string_view extension = "yue"sv; 60const std::string_view extension = "yue"sv;
61 61
62class YueCompilerImpl { 62class YueCompilerImpl {
@@ -7169,7 +7169,7 @@ private:
7169 temp.push_back(indent() + "local "s + tabCheckVar + " = \"table\" == "s + globalVar("type", branch) + '(' + objVar + ')' + nll(branch)); 7169 temp.push_back(indent() + "local "s + tabCheckVar + " = \"table\" == "s + globalVar("type", branch) + '(' + objVar + ')' + nll(branch));
7170 } 7170 }
7171 std::string matchVar; 7171 std::string matchVar;
7172 bool lastBranch = branches.back() == branch_; 7172 bool lastBranch = branches.back() == branch_ && !switchNode->lastBranch;
7173 if (!lastBranch) { 7173 if (!lastBranch) {
7174 matchVar = getUnusedName("_match_"); 7174 matchVar = getUnusedName("_match_");
7175 forceAddToScope(matchVar); 7175 forceAddToScope(matchVar);
@@ -7232,8 +7232,12 @@ private:
7232 } 7232 }
7233 } 7233 }
7234 if (switchNode->lastBranch) { 7234 if (switchNode->lastBranch) {
7235 temp.push_back(indent() + "else"s + nll(switchNode->lastBranch)); 7235 if (!firstBranch) {
7236 pushScope(); 7236 temp.push_back(indent() + "else"s + nll(switchNode->lastBranch));
7237 pushScope();
7238 } else {
7239 addScope--;
7240 }
7237 transform_plain_body(switchNode->lastBranch, temp, usage, assignList); 7241 transform_plain_body(switchNode->lastBranch, temp, usage, assignList);
7238 popScope(); 7242 popScope();
7239 } 7243 }