I tried compiling the factorial example from the paper (Typed Lua: An Optional Type System for Lua) shown below (changed for integers since I'm on 5.3):
local function factorial(n: integer): integer
if n == 0 then
return 1
else
return n * factorial(n - 1)
end
end
local x = 5
print(factorial(x))
This program will not compile in strict mode, which is a bit counter-intuitive. It produces the following error:
typedtest.tl:1:25: type error, return type '(integer, nil*)' does not match '(integer)'
Which makes sense, as normally you'd want an expression list like the expressions in a return statement to have that type, right? Well I don't really know.
I made the change to not append the nil* on strict mode (and this allows the above code to compile). I don't know if this is an appropriate fix, if it breaks other things or not, but I made the PR for your consideration anyway.
EDIT: It's worth pointing out p.3 of the paper, which does make it seem like you should be able to work like this: "There is an optional stricter mode of operation where Typed Lua does not give variadic tails to the parts of function type unless the programmer explicitly declares it, and so will also check all function calls for arity mismatch." Without my change this is not possible for specifying the return part, without giving (... , nil*) manually (or automatically deducing).
I tried compiling the factorial example from the paper (Typed Lua: An Optional Type System for Lua) shown below (changed for integers since I'm on 5.3):
This program will not compile in strict mode, which is a bit counter-intuitive. It produces the following error:
Which makes sense, as normally you'd want an expression list like the expressions in a return statement to have that type, right? Well I don't really know.
I made the change to not append the
nil*
on strict mode (and this allows the above code to compile). I don't know if this is an appropriate fix, if it breaks other things or not, but I made the PR for your consideration anyway.EDIT: It's worth pointing out p.3 of the paper, which does make it seem like you should be able to work like this: "There is an optional stricter mode of operation where Typed Lua does not give variadic tails to the parts of function type unless the programmer explicitly declares it, and so will also check all function calls for arity mismatch." Without my change this is not possible for specifying the return part, without giving
(... , nil*)
manually (or automatically deducing).