Currently when using unpack() or anything that returns multiple values inside a if then else statement, it will only return the first value
local Arguments = {1, 2, 3}
local function Print(...)
print(...) -- Outputs 1, expected output is 1 2 3
end
local Success, Response = pcall(Print, if (Arguments) then unpack(Arguments) else nil)
-- Current workaround, much longer than it needs to be
local Success, Response
if (Arguments) then
Success, Response = pcall(Print, unpack(Arguments))
else
Success, Response = pcall(Print)
end
But then this means something like if true then 1, 2, 3 else 4, 5, 6 would have to be valid, which currently is not, and would be confusing, as if x then y else z is meant to evaluate to a single expression, not several. You could write the expression in this way instead: unpack(if Arguments then Arguments else { })
This would be a breaking change, for example when 1 value is expected and one of the expressions of an if expression results in 0 values:
local function f1(t)
print(type(if t then table.unpack(t) else nil))
end
f1{} --> nil
local function f2(t)
if t then
print(type(table.unpack(t)))
else
print(type(nil))
end
end
f2{} -- error, missing argument #1 to type