Skip to content

Type inference ignores loops #1019

@NyakoFox

Description

@NyakoFox

This works:

---@class MyClass

local thing = nil
if true then
    thing = {} --[[@as MyClass]]
end

-- thing is now MyClass?

This doesn't:

---@class MyClass

local thing = nil
for i = 1, 10 do
    thing = {} --[[@as MyClass]]
end

-- thing is nil

happens for while as well:

---@class MyClass

local thing = nil
while true do
    thing = {} --[[@as MyClass]]
    break
end

-- thing is nil

Metadata

Metadata

Assignees

Labels

No labels
No labels

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