tl
tl copied to clipboard
Lua's grammar vs Teal's cast
This Lua code fails, but it is not an issue because the extra parentheses are useless
(io.stdout):write('one\n')
(io.stdout):write('two\n') -- attempt to call a FILE* value
io.stdout:write('one\n')
io.stdout:write('two\n') -- OK
Now, with Teal, this kind of parentheses is used by cast (and could become widely used)
local record Obj
meth1: function(self: Obj)
end
local t = {}
do
(t as Obj):meth1()
(t as Obj):meth1() -- not a function: nil
end
The generated Lua looks like:
local t = {}
do
(t):meth1()(
t):meth1()
end
The answer is the few used ;
Not sure what we can do about this. It's a known gotcha for Lua...
Filed this one under the "semantics" label because it's the one we use for "surprising behaviors", but it really should be under "syntax" :)