LuaLS / LuaLS/lua-language-server
Generics Return Issue
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
Windows
What is the issue affecting?
Annotations
Expected Behaviour
In this function:
--- Merge two tables together, keys that are the same will use the value from the second table
---@generic K, V, L, W
---@param table1 table<K, V>
---@param table2 table<L, W>
---@return table<K | L, V | W>
function table.merge(table1, table2)
for k, v in pairs(table2) do
table1[k] = v
end
return table1
end
I would expect the return type to be table<K | L, V | W> however it is actually always table<K, V>
There is also a secondary issue here where k, v are seen as unknown when they should be seen as V, W (I assume this is another generics issue)
Actual Behaviour
Reproduction steps
- Copy example code
- Observe result
Additional Notes
No response
Log File
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the annotated table.merge example in the Visual Studio Code extension on Windows. Start by tracing generic annotation and table type inference for @generic, @param, @return, and pairs; done means the return is table<K | L, V | W> and k and v resolve to the second table's types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, vscode
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100