I think it would be good if a typechecker for Lua could report an error in a function like
local function foo(x: number): string
if x == 2 then return nil else return "ok" end
end
much like Typescript does with this one:
function foo(x: number): string
{
if (x == 2) { return null; } else { return "ok"; }
}
On a whim I tried installing tl and seeing what it did.
Sadly it didn't warn or prevent the problem in this example:
% cat foo.tl
local function foo(x: number): string
if x == 2 then return nil else return "ok" end
end
local x = {
foo(1),
foo(2),
foo(3)
}
for i,v in ipairs(x) do print(i,v) end
% tl check foo.tl
========================================
Type checked foo.tl
0 errors detected -- you can use:
tl run foo.tl
to run foo.tl as a program
tl gen foo.tl
to generate foo.lua
% tl run foo.tl
1 ok
% tl --version
0.15.2+dev
Is there a way to have tl report an error in this case like my Typescript example does?
For context, I've been discussing a problem I experienced with Lua some years ago with a fellow on reddit https://old.reddit.com/r/programming/comments/16zmdvy/strong_typing_a_hill_im_willing_to_die_on/k3g2ndf/
I think it would be good if a typechecker for Lua could report an error in a function like
much like Typescript does with this one:
On a whim I tried installing
tl
and seeing what it did. Sadly it didn't warn or prevent the problem in this example:Is there a way to have
tl
report an error in this case like my Typescript example does?