aboutsummaryrefslogtreecommitdiff
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
parent09fc831f540ce3966aeff679164f37e7d40457c9 (diff)
downloadyuescript-e549ca891fc42b78d97df3c46fb83f28bb74e01b.tar.gz
yuescript-e549ca891fc42b78d97df3c46fb83f28bb74e01b.tar.bz2
yuescript-e549ca891fc42b78d97df3c46fb83f28bb74e01b.zip
add a missed local variable check.
-rw-r--r--spec/outputs/syntax.lua11
-rwxr-xr-xsrc/yuescript/yue_compiler.cpp22
2 files changed, 18 insertions, 15 deletions
diff --git a/spec/outputs/syntax.lua b/spec/outputs/syntax.lua
index 4596a29..457f1e1 100644
--- a/spec/outputs/syntax.lua
+++ b/spec/outputs/syntax.lua
@@ -195,9 +195,10 @@ do
195 local _obj_2 = _with_0.a 195 local _obj_2 = _with_0.a
196 _obj_2.c = _obj_2.c + 1 196 _obj_2.c = _obj_2.c + 1
197end 197end
198tb[#tb + 1] = 10 198local _obj_2 = tb
199local _obj_2 = a.b.c 199_obj_2[#_obj_2 + 1] = 10
200_obj_2[#_obj_2 + 1] = 1 200local _obj_3 = a.b.c
201_obj_3[#_obj_3 + 1] = 1
201if v then 202if v then
202 x[#x + 1] = 1 203 x[#x + 1] = 1
203else 204else
@@ -205,12 +206,12 @@ else
205end 206end
206do 207do
207 local _with_0 = tb 208 local _with_0 = tb
208 local _obj_3 = _with_0.b.c 209 local _obj_4 = _with_0.b.c
209 do 210 do
210 local _with_1 = vec 211 local _with_1 = vec
211 _with_1.x = 1 212 _with_1.x = 1
212 _with_1.y = 2 213 _with_1.y = 2
213 _obj_3[#_obj_3 + 1] = _with_1 214 _obj_4[#_obj_4 + 1] = _with_1
214 end 215 end
215end 216end
216x = 0 217x = 0
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()) {