Skip to content

Conversation

@lolleko
Copy link
Member

@lolleko lolleko commented Apr 10, 2023

We try to avoid using select() when we use [0] to access the first value of multiple returns (e.g. multiCall()[0]). In that case, we omit the select(). Unfortunately, this only works if the value is assigned directly (local x = multiCall()). In cases where the value is not assigned, omitting the select and keeping just the call expression (multiCall()) will lead to all return values being passed on. (See #1411)

To fix this, we now wrap the call in parentheses using a new Lua parentheses expression. Using parentheses is the correct way to keep only the first value of multiple returns (see https://www.lua.org/manual/5.1/manual.html#2.5)

TL;DR: multiCall()[0] used to transpile to multiCall() now it transpiles to (multiCall()) which ensures correct semantics across all potential usages.

This fixes #1411

We try to avoid using `select()` when we use `[0]` to access the first value of multiple returns (e.g. `multiCall()[0]`)
In that case, we used to simply omit the `select()`. Unfortunately, this only works if the value is assigned directly (`local x = multiCall()`). In cases where the value is not assigned, omitting the select and keeping the original expression (`multiCall()`) will lead to all return values being passed on.
(See #1411)

To fix this, we now wrap the multireturncall in parentheses. using a new Lua parentheses expression. Using parenthesis is the correct way to keep only the first value of multiple returns (see https://www.lua.org/manual/5.1/manual.html#2.5)

This fixes #1411
@lolleko lolleko requested a review from Perryvw April 10, 2023 22:11
Copy link
Member

@Perryvw Perryvw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using parentheses is a nice tidy way to do this!

@Perryvw Perryvw merged commit d13f800 into master Apr 12, 2023
@Perryvw Perryvw deleted the multi-return-shortuct-broken-1411 branch April 12, 2023 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LuaMultiReturn returns all values even when indexed with [0]

3 participants