LuaLS / LuaLS/lua-language-server
Can not infer basic assignments in nested loop.
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
### Discussed in https://github.com/LuaLS/lua-language-server/discussions/2471
Originally posted by **Luke100000** January 8, 2024
Why can it not infer the type here? How would I rewrite this to be type conform, without spamming type annotations?
```lua
local y = 0
for i = 1, 2 do
y = y + 1 -- here, y is inferred as an integer correctly
for j = 1, 2 do
y = y + 1 -- can not infer type
end
-- sometimes a bit more complexity is required to trigger the issue, so lets add another loop
for j = 1, 2 do
y = y + 1 -- can not infer type
end
end
print(y)
```
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
Start by reproducing the nested-loop example from the issue and read discussion 2471 for the existing analysis. Trace how the language server infers y across the loop assignments. Done means the shown assignments retain the inferred integer type without requiring repeated type annotations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100