moonscript icon indicating copy to clipboard operation
moonscript copied to clipboard

Compile error: transformer.lua:23: table index is nil

Open linkpy opened this issue 5 years ago • 1 comments

variable = \function

Generates the error :

test.moon       Compile error: ...l/share/lua/5.1/moonscript/transform/transformer.lua:23: table index is nil
stack traceback:
        ...l/share/lua/5.1/moonscript/transform/transformer.lua:23: in function <...l/share/lua/5.1/moonscript/transform/transformer.lua:19>
        (tail call): ?
        /usr/local/share/lua/5.1/moonscript/compile.lua:476: in function 'value'
        ...usr/local/share/lua/5.1/moonscript/compile/value.lua:120: in function 'fn'
        /usr/local/share/lua/5.1/moonscript/compile.lua:491: in function 'value'
        ...local/share/lua/5.1/moonscript/compile/statement.lua:96: in function <...local/share/lua/5.1/moonscript/compile/statement.lua:91>
        ...local/share/lua/5.1/moonscript/compile/statement.lua:100: in function 'fn'
        /usr/local/share/lua/5.1/moonscript/compile.lua:530: in function 'stm'
        /usr/local/share/lua/5.1/moonscript/compile.lua:564: in function 'stms'
        ...local/share/lua/5.1/moonscript/compile/statement.lua:235: in function 'fn'
        /usr/local/share/lua/5.1/moonscript/compile.lua:530: in function 'stm'
        /usr/local/share/lua/5.1/moonscript/compile.lua:564: in function </usr/local/share/lua/5.1/moonscript/compile.lua:555>
        (tail call): ?
        /usr/local/share/lua/5.1/moonscript/compile.lua:530: in function 'stm'
        /usr/local/share/lua/5.1/moonscript/compile.lua:564: in function </usr/local/share/lua/5.1/moonscript/compile.lua:555>
        (tail call): ?
        (tail call): ?
  1. I know that in that case the code is invalid, but i found that issue with valid code (within a with block).
  2. Even if the code is erronous, an error like that shouldn't be generated (since it's an internal error).
  3. moonc -T test.moon and moonc -b test.moon generates the same error without displaying more information.

linkpy avatar Oct 21 '20 17:10 linkpy

  1. that's not really a problem with invalid code, but yeah, the fact that it also does this on valid code is bad and IMO makes this a valid issue
  2. that's how all moonscript errors look and while I agree that this is pretty user-unfriendly, I don't think anyone has any plan to change it
  3. they seem to transform the AST before printing anything so they can't be used to debug this

I guess the expected behavior would be that

local c
with a
  c = \b

should be the same as

c = a\b

which would roughly translate to

c = (...) -> a\b ...

as stated by

The with block helps to alleviate this. Within a with block we can use a special statements that begin with either . or \ which represent those operations applied to the object we are using with on.

natnat-mc avatar Oct 21 '20 17:10 natnat-mc