From dce38caac22a024026d19f556aefe0669f97403c Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 29 Jun 2023 14:23:44 +0800 Subject: fix assignment to in-expression with discrete values issue from #140 --- src/yuescript/yue_ast.h | 2 +- src/yuescript/yue_compiler.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h index c47ba8a..85a1e52 100644 --- a/src/yuescript/yue_ast.h +++ b/src/yuescript/yue_ast.h @@ -910,7 +910,7 @@ struct YueFormat { int tabSpaces = 4; std::string toString(ast_node* node); - Converter converter; + Converter converter{}; void pushScope(); void popScope(); std::string convert(const ast_node* node); diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index c1426f9..efd0aed 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -72,7 +72,7 @@ static std::unordered_set Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.17.2"sv; +const std::string_view version = "0.17.3"sv; const std::string_view extension = "yue"sv; class CompileError : public std::logic_error { @@ -5429,7 +5429,13 @@ private: for (auto exp : discrete->values.objects()) { transformExp(static_cast(exp), tmp, ExpUsage::Closure); } - _buf << indent() << "return "sv; + if (usage == ExpUsage::Assignment) { + str_list tmpList; + transformExp(static_cast(assignList->exprs.front()), tmpList, ExpUsage::Closure); + _buf << indent() << tmpList.back() << " = "sv; + } else { + _buf << indent() << "return "sv; + } if (unary_exp->inExp->not_) { _buf << "not ("sv; } -- cgit v1.2.3-55-g6feb