edubart / nelua-lang

Minimal, efficient, statically-typed and meta-programmable systems programming language heavily inspired by Lua, which compiles to C and native code.
https://nelua.io
MIT License
2k stars 62 forks source link

Nelua crashes when using calling a method and the function declaration doesn't contain any parameters #56

Closed Andre-LA closed 3 years ago

Andre-LA commented 3 years ago

Bug description

When trying to use a method on variable which the type actually declares, but in this declaration there is no parameters, the Nelua compiler crashes and gives the compiler's traceback instead of giving an error message.

Code example

local R = @record{a: integer}

function R.hello()
  print'hello'
end

local x: R = {}
x:hello()

This problem doesn't happens when the : syntax sugar is not used:

local R = @record{a: integer}

function R.hello()
  print'hello'
end

local x: R = {}
R.hello(x)

output:

 nelua ../teste.nelua 
../teste.nelua:8:8: error: in call of function 'R.hello': expected at most 0 arguments but got 1
R.hello(x)
       ^~~

Expected behavior

An error message is expected, something like the output when not using the : syntax sugar.

Environment

edubart commented 3 years ago

Fixed and added a test case for this in the spec, thanks for the report!