leafo/moonscript

destructuring a list comprehensions and loops produces invalid code

s-ol opened this issue · 9 comments

s-ol commented
{ 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}]
s-ol commented

This also happens with plain for loops, e.g.

{a, b, c} = for i=1,3
  "item-#{i}"

compiles to

do
  local _accum_0 = { }
  local _len_0 = 1
  for i = 1, 3 do
    _accum_0[_len_0] = "item-" .. tostring(i)
    _len_0 = _len_0 + 1
  end
  local a, b, c
  a, b, c = _accum_0[1], _accum_0[2], _accum_0[3]
end

again, the local a, b, c should be outside of the do ... end scope, not inside. Another workaround is to assign the result of the loop / list comprehension to a temporary variable, which doesn't trigger this bug, and then destructure in a separate statement:

tmp = for i=1,3
  "item-#{i}"
{a,b,c} = tmp

I notice this bug has been completely ignored by the project maintainers for almost two years. Therefore, I have to enquire: is this project dead?

s-ol commented

@Sod-Almighty Well, that depends on what you consider "dead" I guess.

"the maintainers" basically refers to @leafo alone. There isn't much motion in the repo here, mostly because the language overall is very stable (this is one of the two only bugs I've hit in some five years of writing MoonScript, and I've only hit it twice to date). The majority of issues are suggestions of changes to the language, and there is not much interest overall on going through with them since very few of them would possibly be backwards-compatible and there is enough production MoonScript out there for this to matter. Essentially MoonScript might just be "done", you could say.

Certainly issues like this not being fixed is a nuisance, but you could always PR (or fork and put up your version on luarocks).

  • I found about a dozen bugs in the first two pages of issues alone.

  • There are 12 pending merge requests, some (all?) of which have been ignored for over a year.

  • Some modern LUA features are literally impossible to use from Moon, such as issue #402.

I'd say the project was well and truly dead. If the sole maintainer isn't prepared to put in the effort, he should promote other contributors to the role. As things stand, I won't be touching this unmaintained language with a ten-foot barge pole until the situation improves.

And no, I couldn't "PR". Because if I did, leafo would completely bloody ignore me just like he is ignoring you.

s-ol commented

Well give the language a shot and let me know if you actually hit any of those dozen bugs. Or maybe ask the people who reported them how they feel about them not being fixed? I for one reported this here not because I think I deserve this to work better, but to help the project.

And no, I couldn't "PR". Because if I did, leafo would completely bloody ignore me just like he is ignoring you.

That's why I said you can fork it. Go ahead and merge those PRs!

As things stand, I won't be touching this unmaintained language with a ten-foot barge pole until the situation improves.

Great!

I for one reported this here not because I think I deserve this to work better, but to help the project

Then you wasted your time and effort, because he clearly doesn't give a damn.

Take it easy, it is the way an open source project could be. Since it's MIT Licensed, it is not an obligation for the author to maintain this software. I'm a hardcore fun of Moonscript as well. So I studied the sources then wrote a project named Yuescript to push this language to go forward. Most of the issues mentioned in Moonscript repo was been fixed in Yuescript project. You could have a look.

Yes, I will take a look at Yuescript. Thank you.