diff --git a/moonscript/compile/statement.lua b/moonscript/compile/statement.lua index 4c42a58..7c904d4 100644 --- a/moonscript/compile/statement.lua +++ b/moonscript/compile/statement.lua @@ -157,6 +157,9 @@ line_compile = { }), " do") do local _with_0 = self:block(loop) + _with_0:declare({ + name + }) _with_0:stms(block) return _with_0 end @@ -195,6 +198,7 @@ line_compile = { end do local _with_0 = self:block(loop) + _with_0:declare(names) _with_0:stms(block) return _with_0 end diff --git a/moonscript/compile/statement.moon b/moonscript/compile/statement.moon index 0381afc..226eac0 100644 --- a/moonscript/compile/statement.moon +++ b/moonscript/compile/statement.moon @@ -91,6 +91,7 @@ line_compile = _, name, bounds, block = unpack node loop = @line "for ", @name(name), " = ", @value({"explist", unpack bounds}), " do" with @block loop + \declare {name} \stms block -- for x in y ... @@ -106,6 +107,7 @@ line_compile = \append " do" with @block loop + \declare names \stms block export: (node) => diff --git a/tests/outputs/lists.lua b/tests/outputs/lists.lua index b468256..d0a24a4 100644 --- a/tests/outputs/lists.lua +++ b/tests/outputs/lists.lua @@ -197,8 +197,8 @@ local hello = (function() for _index_0 = 1, #_list_1 do x = _list_1[_index_0] local _list_2 = items - for _index_0 = 1, #_list_2 do - local y = _list_2[_index_0] + for _index_1 = 1, #_list_2 do + local y = _list_2[_index_1] _len_0 = _len_0 + 1 _accum_0[_len_0] = x + y end