rvirding / luerl

Lua in Erlang
Apache License 2.0
1.03k stars 141 forks source link

Support compilation with Erlang/OTP 27.0-rc1 #173

Closed badlop closed 7 months ago

badlop commented 7 months ago

Compiling Luerl with Erlang/OTP 27.0-rc1 fails with error message syntax error before: 'else':

``` $ make erlc -W1 -o ./ebin -DERLANG_VERSION=\"27.0-rc1\" -DHAS_MAPS=true -DHAS_FULL_KEYS=true -DNEW_REC_CORE=true -DNEW_RAND=true -DNEW_BOOL_GUARD=true -DHAS_FLOOR=true -DHAS_CEIL=true -DNEW_STACKTRACE=true -DEEP48=true -W1 src/Elixir.Luerl.erl erlc -W1 -o ./ebin -DERLANG_VERSION=\"27.0-rc1\" -DHAS_MAPS=true -DHAS_FULL_KEYS=true -DNEW_REC_CORE=true -DNEW_RAND=true -DNEW_BOOL_GUARD=true -DHAS_FLOOR=true -DHAS_CEIL=true -DNEW_STACKTRACE=true -DEEP48=true -W1 src/Elixir.Luerl.New.erl erlc -W1 -o ./ebin -DERLANG_VERSION=\"27.0-rc1\" -DHAS_MAPS=true -DHAS_FULL_KEYS=true -DNEW_REC_CORE=true -DNEW_RAND=true -DNEW_BOOL_GUARD=true -DHAS_FLOOR=true -DHAS_CEIL=true -DNEW_STACKTRACE=true -DEEP48=true -W1 src/luerl_anno.erl erlc -W1 -o ./ebin -DERLANG_VERSION=\"27.0-rc1\" -DHAS_MAPS=true -DHAS_FULL_KEYS=true -DNEW_REC_CORE=true -DNEW_RAND=true -DNEW_BOOL_GUARD=true -DHAS_FLOOR=true -DHAS_CEIL=true -DNEW_STACKTRACE=true -DEEP48=true -W1 src/luerl_app.erl erlc -W1 -o ./ebin -DERLANG_VERSION=\"27.0-rc1\" -DHAS_MAPS=true -DHAS_FULL_KEYS=true -DNEW_REC_CORE=true -DNEW_RAND=true -DNEW_BOOL_GUARD=true -DHAS_FLOOR=true -DHAS_CEIL=true -DNEW_STACKTRACE=true -DEEP48=true -W1 src/luerl_comp_cg.erl src/luerl_comp.hrl:77:30: syntax error before: 'else' % 77| -record(if_stmt, {l,tests=[],else}). % | ^ src/luerl_comp_cg.erl:222:27: syntax error before: 'else' % 222| if_stmt(#if_stmt{tests=Ts,else=E}, St) -> % | ^ src/luerl_comp_cg.erl:89:6: record if_stmt undefined % 89| stmt(#if_stmt{}=I, _, St) -> if_stmt(I, St); % | ^ src/luerl_comp_cg.erl:89:30: function if_stmt/2 undefined % 89| stmt(#if_stmt{}=I, _, St) -> if_stmt(I, St); % | ^ src/luerl_comp_cg.erl:225:1: Warning: function if_tests/3 is unused % 225| if_tests([{E,B}], #block{body=[]}, St0) -> % | ^ make: *** [Makefile:53: ebin/luerl_comp_cg.beam] Error 1 ```

This is because else is now a reserved keyword, similarly to maybe. The solution is quite simple: quote else to ensure the compiler treats it as an atom and not a keyword.

https://erlang.org/documentation/doc-15.0-rc1/doc/upcoming_incompatibilities.html#feature-maybe_expr-will-be-enabled-by-default

rvirding commented 7 months ago

That would work but I was thinking along the lines of:

-record(if_stmt, {line, test_blocks, else_block}).

which is bit more informative and get away from my ultra short keys. :smile: Do you know if I can make these changes to the PR ans still use it.

badlop commented 7 months ago

Ah, right! it seems preferable to use a specific atom instead of 'else'.

For example, I tipically search over the source code a lot, and having a specific name like else_block (or whatever) will help me to find where that element is used in the code.

Ok, I've force-pushed a modified commit, and now the PR shows that improvement.