summaryrefslogtreecommitdiff
path: root/src/yuescript/yue_compiler.cpp
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-02-11 11:14:00 +0800
committerLi Jin <dragon-fly@qq.com>2022-02-11 11:14:00 +0800
commite549ca891fc42b78d97df3c46fb83f28bb74e01b (patch)
tree4d3e26824c43f92597694885e842e622dc01e9c4 /src/yuescript/yue_compiler.cpp
parent09fc831f540ce3966aeff679164f37e7d40457c9 (diff)
downloadyuescript-e549ca891fc42b78d97df3c46fb83f28bb74e01b.tar.gz
yuescript-e549ca891fc42b78d97df3c46fb83f28bb74e01b.tar.bz2
yuescript-e549ca891fc42b78d97df3c46fb83f28bb74e01b.zip
add a missed local variable check.
Diffstat (limited to '')
-rwxr-xr-xsrc/yuescript/yue_compiler.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 33d4dcb..6617ec5 100755
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -2023,17 +2023,9 @@ private:
2023 throw std::logic_error(_info.errorMessage("can not apply update to a metatable"sv, leftExp)); 2023 throw std::logic_error(_info.errorMessage("can not apply update to a metatable"sv, leftExp));
2024 } 2024 }
2025 BLOCK_START 2025 BLOCK_START
2026 BREAK_IF(chain->items.size() < 2);
2027 if (chain->items.size() == 2) {
2028 if (auto callable = ast_cast<Callable_t>(chain->items.front())) {
2029 ast_node* var = callable->item.as<Variable_t>();
2030 if (auto self = callable->item.as<SelfName_t>()) {
2031 var = self->name.as<self_t>();
2032 }
2033 BREAK_IF(var);
2034 }
2035 }
2036 if (op == "#"sv) { 2026 if (op == "#"sv) {
2027 auto varName = singleVariableFrom(chain);
2028 BREAK_IF(!varName.empty() && isLocal(varName));
2037 auto objVar = getUnusedName("_obj_"sv); 2029 auto objVar = getUnusedName("_obj_"sv);
2038 auto newAssignment = x->new_ptr<ExpListAssign_t>(); 2030 auto newAssignment = x->new_ptr<ExpListAssign_t>();
2039 newAssignment->expList.set(toAst<ExpList_t>(objVar, x)); 2031 newAssignment->expList.set(toAst<ExpList_t>(objVar, x));
@@ -2044,6 +2036,16 @@ private:
2044 chain->items.clear(); 2036 chain->items.clear();
2045 chain->items.push_back(toAst<Callable_t>(objVar, x)); 2037 chain->items.push_back(toAst<Callable_t>(objVar, x));
2046 } else { 2038 } else {
2039 BREAK_IF(chain->items.size() < 2);
2040 if (chain->items.size() == 2) {
2041 if (auto callable = ast_cast<Callable_t>(chain->items.front())) {
2042 ast_node* var = callable->item.as<Variable_t>();
2043 if (auto self = callable->item.as<SelfName_t>()) {
2044 var = self->name.as<self_t>();
2045 }
2046 BREAK_IF(var && isLocal(_parser.toString(var)));
2047 }
2048 }
2047 auto tmpChain = x->new_ptr<ChainValue_t>(); 2049 auto tmpChain = x->new_ptr<ChainValue_t>();
2048 ast_ptr<false, ast_node> ptr(chain->items.back()); 2050 ast_ptr<false, ast_node> ptr(chain->items.back());
2049 for (auto item : chain->items.objects()) { 2051 for (auto item : chain->items.objects()) {