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

upgrade from 3.6.3 to 3.6.4 broke the type detection of nested objects when @cast is used #1737

Closed
muppet9010 opened this issue Nov 29, 2022 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@muppet9010
Copy link

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?

Annotations, Type Checking

Expected Behaviour

In 3.6.3 the code in Reproduction Steps has the value of x resolving to the correct type.

Actual Behaviour

In 3.6.4 this is no longer the case and gives the error:

"code": "no-unknown",
"severity": 4,
"message": "Can not infer type.",
"source": "Lua Diagnostics.",

image

Reproduction steps

---@class Container
---@field object Object

---@class Object
---@field speed number?

local object, x
local things ---@type Container[]

for _, thing in pairs(things) do
    object = thing.object
    x = object.speed ---@cast x - nil
end

Additional Notes

No response

Log File

No response

@muppet9010 muppet9010 changed the title 3.6.3 to 3.6.4 broke the type detection of nested objects upgrade from 3.6.3 to 3.6.4 broke the type detection of nested objects Nov 29, 2022
@muppet9010 muppet9010 changed the title upgrade from 3.6.3 to 3.6.4 broke the type detection of nested objects upgrade from 3.6.3 to 3.6.4 broke the type detection of nested objects when @cast is used Nov 29, 2022
@sumneko sumneko added the bug Something isn't working label Nov 30, 2022
@sumneko sumneko added this to the 3.7.0 milestone Nov 30, 2022
@muppet9010
Copy link
Author

muppet9010 commented Dec 8, 2022

So it appears this isn't related to the @cast. As the issue occurs without it, it can just take an extra save of the file for the plugin to realise it's unhappy and raise the warning.

---@class Container
---@field object Object

---@class Object
---@field speed number?

local object, x
local things ---@type Container[]

for _, thing in pairs(things) do
    object = thing.object
    x = object.speed
end

This also shows the issue, but it can take the plugin a bit to flag that x is unknown and raise this is a warning. If it seems happy either just save the file again unchanged can often raise the warning otherwise; make it invalid code (remove d off last end) and save it, then put the d back and save it again.

@sumneko
Copy link
Collaborator

sumneko commented Dec 16, 2022

fixed by new tracer

@sumneko sumneko closed this as completed Dec 16, 2022
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

2 participants