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
1.99k stars 64 forks source link

Confusing errors with varargs #244

Open jrfondren opened 9 months ago

jrfondren commented 9 months ago

Bug description

... seems to be a special name in two ways that aren't mentioned by the Overview: it's not otherwise a valid identifier, and a : varargs parameter not given that name is treated as : integer.

Code example

Type error in Nelua:

local function f(items: varargs)
  print(#items) -- error: in unary operation `len`: invalid operation for type 'int64'
end

f(1, 2, 3)

Codegen error:

local function f(items: varargs) -- void va1_f_1(int64_t items)
end

f(1, 2, 3) -- error: too many arguments to function ‘va1_f_1’

Workaround

There's no problem if you write code that uses ...: varargs like in the Overview.

More ... development also seems to be waiting on the any type, based on tests like

it("any type", function()
...
  expect.run_error_c([[
    local function f(...) return ... end
  ]], "not supported yet")

Environment

x86_64 linux Nelua 0.2.0-dev Build number: 1610 Git date: 2023-11-19 16:54:45 -0300 Git hash: e82695abf0a68a30a593cefb0bf1143cf9e14b6b Semantic version: 0.2.0-dev.1610+e82695ab Copyright (C) 2019-2023 Eduardo Bart (https://nelua.io/)