pigpigyyy / Yuescript

A Moonscript dialect compiles to Lua.
http://yuescript.org
MIT License
424 stars 35 forks source link

Macros are broken (outside of the online REPL) #134

Closed SkyyySi closed 1 year ago

SkyyySi commented 1 year ago

The code

macro INVERT = (var) ->
    "#{var} = not #{var}"

$INVERT(x)

used to be valid and produce the following Lua code:

local x = 5;
x = not x

However, after having installed Yuescript 0.16.5, this behavior seems to be broken, with it now resulting in the following compilation error:

Failed to compile: test2.yue
5: left hand expression is not assignable
$INVERT(x)
^

However, weirdly, the online REPL seems to be unaffected by this.

pigpigyyy commented 1 year ago

Can you show me the full codes in your "test2.yue" ?

SkyyySi commented 1 year ago

Can you show me the full codes in your "test2.yue" ?

Sure:

macro INVERT = (var) ->
    print(var)
    "#{var} = not #{var}"

$INVERT(x)

The print statement prints that var is a nil value (note to self: why did strip that line out? That sounds like it's quite important here).

For good measure, I also tested this in the interactive (offline) REPL:

macro test = (x, y, z) -> "'#{x}, #{y}, #{z}'"

When running that code as $test("foo", "bar", "biz"), I get back the string nil, nil, nil.


In case that helps, here's some info on my specific setup (since this issue doesn't occur in the online REPL, this issue may be related to that):

I think the previous version of Yuescript I used was 0.16.1, but I also recently compiled just fine on a different, more recent setup on my laptop, so I'm guessing that this issue was only introduced in 0.16.5 or maybe 0.16.4.

pigpigyyy commented 1 year ago

Found there were wrong arguments passing while expanding macro. The problem was there for a long time and lacking test cases to reveal it. Should be fixed by 78433df36c5b492f366ba57d852f5393b786cfff now.