Skip to content

Typing for variables partially works. #1367

Closed
@muppet9010

Description

@muppet9010

In the below I am trying to set the type of the variable i in a for loop. the on-hover looks correct when done with @type, but it fails to evaluate correctly when used, however the cast works as expected.

---@class integerA : integer
local list = {} ---@type table<integerA, table>

---@type integerA
for i = 1, 10 do
    list[i] = {} --- This `i` says its type integerA, however the line gives an error of "Can not infer type. LuaDiagnostics.(no-unknown)"
end

for i = 1, 10 do
    ---@cast i integerA
    list[i] = {}
end

I believe the @type method is "better" than cast as it feels a more natural way to define its type, rather than forcing the variable to be viewed as having a set type with cast.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions