Skip to content

Can not infer basic assignments in nested loop. #2494

@Luke100000

Description

@Luke100000

Discussed in #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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions