Skip to content

destructuring a list comprehensions and loops produces invalid code #411

Description

@s-ol
{ a, b, c } = [a * 2 for a in *{ 1, 2, 3}]

in http://moonscript.org/compiler/:

do
  local _accum_0 = { }
  local _len_0 = 1
  local _list_0 = {
    1,
    2,
    3
  }
  for _index_0 = 1, #_list_0 do
    local a = _list_0[_index_0]
    _accum_0[_len_0] = a * 2
    _len_0 = _len_0 + 1
  end
  local a, b, c
  a, b, c = _accum_0[1], _accum_0[2], _accum_0[3]
end

leading to undefined reference to global errors in very unexpected ways.
Temporary workaround is to manually declare a,b,c like so:

local a, b, c
{ a, b, c } = [a * 2 for a in *{ 1, 2, 3}]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions