tl icon indicating copy to clipboard operation
tl copied to clipboard

Lua's grammar vs Teal's cast

Open fperrad opened this issue 1 year ago • 2 comments

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

fperrad avatar Mar 18 '24 18:03 fperrad

The answer is the few used ;

fperrad avatar Mar 18 '24 19:03 fperrad

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" :)

hishamhm avatar Mar 19 '24 19:03 hishamhm