Skip to content

Typing for variables partially works. #1367

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

Closed
muppet9010 opened this issue Jul 21, 2022 · 3 comments
Closed

Typing for variables partially works. #1367

muppet9010 opened this issue Jul 21, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@muppet9010
Copy link

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.

@sumneko sumneko added the bug Something isn't working label Jul 22, 2022
@nathanrpage97
Copy link

I don't see the issue when running 3.5.0

@muppet9010
Copy link
Author

muppet9010 commented Jul 23, 2022

Maybe it's somehow from my Sumneko extension settings, as I do have a fair few non default. When I'm back on the pc I shall extract and upload them.
I am running the 3.5.0 public realease.

@muppet9010
Copy link
Author

My extension settings are below in case any are somehow relevant.
The fact I have strong enabled to flag unknown typed variables is the only one I assume is relevant given the diagnostic warning that was being raised.

settings.json.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants