lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Can not infer basic assignments in nested loop.

Open Luke100000 opened this issue 1 year ago • 1 comments

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?

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)

Luke100000 avatar Jan 23 '24 17:01 Luke100000

https://github.com/LuaLS/lua-language-server/issues/2236

RomanSpector avatar Feb 01 '24 11:02 RomanSpector