Skip to content

destructing assignment works wrong with for generator #449

Description

@INoorik

Code like this

{a, b} = for i in *{2, 3} do i*i

print a, b

Compiles to

do
  local _accum_0 = { }
  local _len_0 = 1
  local _list_0 = {
    2,
    3
  }
  for _index_0 = 1, #_list_0 do
    local i = _list_0[_index_0]
    _accum_0[_len_0] = i * i
    _len_0 = _len_0 + 1
  end
  local a, b
  a, b = _accum_0[1], _accum_0[2]
end
return print(a, b)

There variables a and b are local, so execution result is nil nil instead of 4 9

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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