Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
arnoson opened this issue Sep 13, 2023 · 2 comments
Open

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

arnoson opened this issue Sep 13, 2023 · 2 comments
Labels
bug Something isn't working feat/diagnostics Related to the diagnostics feature

Comments

@arnoson
Copy link

arnoson commented Sep 13, 2023

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

@PinewoodPip
Copy link

PinewoodPip commented Sep 13, 2023

See this for a workaround and more details: #2207
TL;DR: add a newline at the end of the file.

@arnoson
Copy link
Author

arnoson commented Sep 13, 2023

Thanks @PinewoodPip for the quick answer! I didn't search in the discussions 🙈

@carsakiller carsakiller added bug Something isn't working feat/diagnostics Related to the diagnostics feature labels Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feat/diagnostics Related to the diagnostics feature
Projects
None yet
Development

No branches or pull requests

3 participants