From 7682305156719aad1397d9eb63e97ecdb8393316 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 30 Jun 2020 12:15:25 +0800 Subject: fix issue when declaring multiple variables with attribute. --- spec/inputs/attrib.moon | 7 +++++-- src/MoonP/moon_compiler.cpp | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/spec/inputs/attrib.moon b/spec/inputs/attrib.moon index a5fa376..bc1e67e 100644 --- a/spec/inputs/attrib.moon +++ b/spec/inputs/attrib.moon @@ -1,6 +1,9 @@ do - close a = setmetatable {},__close:=> print "closed" - const a = 123 + close a, b = setmetatable {},__close:=> print "closed" + const c, d = 123, 'abc' + + close a, b + const c, d do close v = if flag diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index 8dc5c94..a3ed4de 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp @@ -5126,6 +5126,7 @@ private: auto expList = x->new_ptr(); str_list tmpVars; str_list vars; + pushScope(); for (auto name : localAttrib->nameList->names.objects()) { auto callable = x->new_ptr(); callable->item.set(name); @@ -5136,9 +5137,11 @@ private: auto exp = newExp(value, x); expList->exprs.push_back(exp); tmpVars.push_back(getUnusedName("_var_"sv)); + addToScope(tmpVars.back()); vars.push_back(_parser.toString(name)); } - auto tmpVarStr = join(tmpVars, ","sv); + popScope(); + auto tmpVarStr = join(tmpVars, ", "sv); auto tmpVarList = toAst(tmpVarStr, x); auto assignment = x->new_ptr(); assignment->expList.set(tmpVarList); @@ -5150,7 +5153,7 @@ private: forceAddToScope(var); var.append(attrib); } - temp.push_back(indent() + s("local "sv) + join(vars) + s(" = "sv) + tmpVarStr + nll(x)); + temp.push_back(indent() + s("local "sv) + join(vars, ", "sv) + s(" = "sv) + tmpVarStr + nll(x)); out.push_back(join(temp)); } -- cgit v1.2.3-55-g6feb