tl
tl copied to clipboard
edge case of checking of the number of return value
local function bar()
end
local function foo()
if true then
return bar() -- ERROR: in return value: excess return values, expected 0 (), got 1 (())
else
bar()
return -- OK but not idiomatic
end
end
Note: with nil as explicit return, the checker is happy
local function bar(): nil
end
local function foo(): nil
return bar()
end
Thanks for the report! This is definitely a bug that needs fixing.
return bar()
Is the goal here to trigger a tail call? It surprised me a bit which of the two options you marked as idiomatic — I usually never return f() from 0-ary functions, to help the reader spot that nothing is being returned.
I guess it varies but I tend to agree with @fperrad: I always return f() from 0-ary functions in Lua, in part because of the tail call.