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

Cannot call methods using method syntax sugar with comptime arguments #45

Closed Andre-LA closed 3 years ago

Andre-LA commented 3 years ago

Base code to reproduce:

local X = @record{y: integer}

function X:A(a: facultative(stringview) <comptime>)
  ## if a.type.is_niltype then
    print'A is niltype'
  ## else
    print(#['a is ' .. a.value]#)
  ## end
end

Using it without method call syntax sugar works:

local z: X = {0}

X.A(z)
print'---'
X.A(z, 'hello world')

However, using the syntax sugar produces an error:

local z: X = {0}

z:A()
print'---'
z:A('hello world')

error code (gcc):

C compilation for 'nelua_cache/testes' failed:
nelua_cache/testes.c: In function ‘nelua_main’:
nelua_cache/testes.c:90:28: error: incompatible type for argument 2 of ‘testes_X_A__2’
   90 |   testes_X_A__2(&testes_z, ((nlstringview){(uint8_t*)__strlit4, 11}));
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                            |
      |                            nlstringview
nelua_cache/testes.c:80:49: note: expected ‘nlniltype’ but argument is of type ‘nlstringview’
   80 | void testes_X_A__2(testes_X_ptr self, nlniltype a) {
      |                                       ~~~~~~~~~~^
edubart commented 3 years ago

Yea it's a bug.

edubart commented 3 years ago

Fixed in a recent commit, check if works for you so we can close.

Andre-LA commented 3 years ago

Fixed, thanks! :D

Also tested on a more complex case, it's also fixed there

Closing issue :)