From 5ad0f4daa8171460dc71332669c365bb8e07dab0 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 2 Nov 2023 12:27:27 +0800 Subject: fix table matching syntax in switch statement with list table. --- src/yuescript/yue_compiler.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 648dab2..1733967 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -75,7 +75,7 @@ static std::unordered_set Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.20.3"sv; +const std::string_view version = "0.20.4"sv; const std::string_view extension = "yue"sv; class CompileError : public std::logic_error { @@ -9155,8 +9155,15 @@ private: for (auto branch_ : branches) { auto branch = static_cast(branch_); auto valueList = static_cast(branch->condition.get()); - if (auto value = singleValueFrom(valueList); - value && (value->item.is() || value->get_by_path())) { + bool tableMatching = false; + if (auto value = singleValueFrom(valueList)) { + if (value->item.is()) { + tableMatching = true; + } else if (auto sVal = value->item.as()){ + tableMatching = ast_is(sVal->value); + } + } + if (tableMatching) { if (!firstBranch) { temp.push_back(indent() + "else"s + nll(branch)); pushScope(); -- cgit v1.2.3-55-g6feb