Skip to content

unknown-cast-variable in last function of a file #2326

Description

@arnoson

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Type Checking

Expected Behaviour

I have a file with two functions that both cast a local variable to a different type. This works perfectly for the first function but fails for the second (or the last if I add more functions).

Actual Behaviour

Error Unknown type conversion variable item (unknown-cast-variable) for the ---@cast item B inside fu().

Reproduction steps

---@alias A table
---@alias B table

---@type table<number, A>
local items = {}

function fu()
  local item = items[1]
  ---@cast item B
end

function bar()
  local item = items[1]
  -- Error appears here:
  ---@cast item B
end

Additional Notes

No response

Log File

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfeat/diagnosticsRelated to the diagnostics feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions