Typecasting truncates tuple returns

When you try to return a tuple implicitly, such as by returning the output of a separate function, you will normally pass the tuple along correctly.

function numbers()
   return 1, 2, 3
end
function echo()
   return numbers()
end
print(echo()) --> 1 2 3

But if you typecast the implicit tuple, it will truncate as if you had placed it in parentheses.

function numbers()
   return 1, 2, 3
end
function echo()
   return numbers() :: any
end
print(echo()) --> 1

Expected behavior

Type annotations shouldn’t have any effect on interpreted script behavior. The typecast causing an alternative interpretation is surprising and unexpected and it appears to be the only place where type annotations change your script behavior.

7 Likes

This is intended by the design of the operator, which can be viewed here: rfcs/docs/syntax-type-ascription.md at master · luau-lang/rfcs · GitHub