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
I might be wrong here, but I assume this should work?
Language server should detect the types from the defined tuple:
---@aliasmy_tuple{ [1]: integer, [2]: boolean }---@typemy_tuplelocaltuple= {1, true}
--- This works!locala, b=tuple[1], tuple[2]
--- This gets "integer" for "c", but "unknown" for "d:localc, d=table.unpack(tuple)
Actual Behaviour
---@aliasmy_tuple{ [1]: integer, [2]: boolean }---@typemy_tuplelocaltuple= {1, true}
--- "c" should be "integer" and "d" "boolean":localc, d=table.unpack(tuple)
Reproduction steps
Define tuple like I did
Create such tuple
unpack to two variables
Additional Notes
I'm not sure if this is a feature that is even considered, but since I do use unpack sometimes to destructure tuples into their distinct variables, I feel this would be a good feature to have.
Log File
No response
The text was updated successfully, but these errors were encountered:
It is using a T[] to match the list. Although T is a generic type, is can only match one type (or a union type) => homogeneous array
In this case luals might be inferring that tuple is an array of integer|boolean => so it matches T to integer|boolean
And finally it is trying to return T ... (variadic return) but unfortunately, the generic support of luals is quite limited as seems currently no way to return variadic generic type, so we are getting d: unknown ...
Hack annotation?
In this PR #2587, @lewis6991 tried with with a "hack" to annotate unpack
This seems to support up to 9 unpack values of different types, which I believe it is more than enough to solve most common cases 👍
I just tried to copy this annotation to table.unpack, however, seems not working well ☹️
How are you using the lua-language-server?
Other
Which OS are you using?
Windows
What is the issue affecting?
Diagnostics/Syntax Checking
Expected Behaviour
I might be wrong here, but I assume this should work?
Language server should detect the types from the defined tuple:
Actual Behaviour
Reproduction steps
unpack
to two variablesAdditional Notes
I'm not sure if this is a feature that is even considered, but since I do use unpack sometimes to destructure tuples into their distinct variables, I feel this would be a good feature to have.
Log File
No response
The text was updated successfully, but these errors were encountered: