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. --- src/MoonP/moon_compiler.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') 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