When a function returns a table, MoonScript allows us to use a destructuring assignment to assign values from the table directly to variables in our scope.
However, when we mix a destructuring assignment with assigning from additional return values from the function, the compiled code behaves as if those additional return values are all nil.
Here's a minimal reproduction scenario to clarify:
fun =()->
my_table ={a:1,b:2}return my_table,2{a: my_a,b: my_b }, my_c = fun!This generates the following Lua code:
localfunfun=function()
localmy_table= {
a=1,
b=2
}
returnmy_table, 2endlocalmy_a, my_bdolocal_obj_0=fun()
my_a, my_b=_obj_0.a, _obj_0.bendlocalmy_c=nilWhen the proper output should be along the lines of:
localfunfun=function()
localmy_table= {
a=1,
b=2
}
returnmy_table, 2endlocalmy_a, my_b, my_cdolocal_obj_0, my_c=fun()
my_a, my_b=_obj_0.a, _obj_0.bendI'm seeing this issue with the latest MoonScript release, 0.5.0-1.
This doesn't sound like a terribly difficult fix, so if no one starts working on it soon, I'll probably be able to fix it and contribute a pull request.
When a function returns a table, MoonScript allows us to use a destructuring assignment to assign values from the table directly to variables in our scope.
However, when we mix a destructuring assignment with assigning from additional return values from the function, the compiled code behaves as if those additional return values are all nil.
Here's a minimal reproduction scenario to clarify:
This generates the following Lua code:
When the proper output should be along the lines of:
I'm seeing this issue with the latest MoonScript release,
0.5.0-1.This doesn't sound like a terribly difficult fix, so if no one starts working on it soon, I'll probably be able to fix it and contribute a pull request.