You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pcall() is declared to return LuaMultiReturn<[true, R] | [false, string]>, but in Lua, the error object can be anything. This leads to problem when the error object is used in a context where it matters whether it can be something other than a string.
Function foo() throws an empty object. To allow concatenation with a string, a call to tostring() needs to be inserted, but it isn't. So the concatenation in the argument to print() fails:
Lua execution error:
[string "--[[ Generated with https://github.com/TypeSc..."]:7: attempt to concatenate a table value (field '?')
If the correct type is added to the declaration of result, the call to tostring() is inserted:
letresult: [true,void]|[false,unknown]=pcall(foo)
Generated code:
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]functionfoo()
error({}, 0)
endresult= {pcall(foo)}
ifnotresult[1] thenprint("error: " ..tostring(result[2]))
end
Expected behavior
I think that the return type of pcall() should be changed to LuaMultiReturn<[true, R] | [false, unknown]>. The same applies to coroutine.resume().
The text was updated successfully, but these errors were encountered:
Description
pcall()
is declared to returnLuaMultiReturn<[true, R] | [false, string]>
, but in Lua, the error object can be anything. This leads to problem when the error object is used in a context where it matters whether it can be something other than a string.To reproduce
Consider the following example (playground):
Function
foo()
throws an empty object. To allow concatenation with a string, a call totostring()
needs to be inserted, but it isn't. So the concatenation in the argument toprint()
fails:If the correct type is added to the declaration of
result
, the call totostring()
is inserted:Generated code:
Expected behavior
I think that the return type of
pcall()
should be changed toLuaMultiReturn<[true, R] | [false, unknown]>
. The same applies tocoroutine.resume()
.The text was updated successfully, but these errors were encountered: