seaofvoices / darklua

A command line tool that transforms Lua code
https://darklua.com/
MIT License
78 stars 10 forks source link

Application of 'remove_types' can change runtime behavior where a function call has a type assertion #140

Closed sircfenner closed 10 months ago

sircfenner commented 10 months ago

Adding a type assertion to a function call has the (runtime) effect of truncating any returned values to a maximum of one value:

local function multipleReturns()
    return 1, 2
end
print(multipleReturns() :: any)

This will output "1".

Currently, the 'remove_types' rule translates line 4 as:

print(multipleReturns())

This will output both "1" and "2", incorrectly.

The 'remove_types' rule should wrap these type-asserted calls in parentheses:

print((multipleReturns()))

This will output "1", correctly.

jeparlefrancais commented 10 months ago

Good catch! This should be a simple fix, I already have this kind of verification in other parts of darklua