You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have found that in a specific case the nil type isn't being correctly removed and re-added to a variables type list.
See the comments below in an abstracted example of the issue:
---@class data
---@field things table<integer, thing>
---@class thing
---@field child child
---@class child
---@field test test
---@class test
---@field valid boolean
---@field value number
---@type data
local data = {
things = {
{
child = {
test = {
value = 0.1,
valid = false
}
}
},
{
child = {
test = {
value = 2,
valid = false
}
}
}
}
}
local x ---@type thing|nil
local index ---@type integer|nil
while x == nil do
index = next(data.things)
x = data.things[index]
if x == nil then
-- no new data found
return
end
if not x.child.test.valid then -- x should not have nil as a possible type here. In my live code this gives a "need-check-nil" warning.
-- not valid so discard it from the list
data.things[index] = nil
x = nil
end
local checkXType = x -- This should have x as: thing|nil
end
local textToPrint = x.child.test.value -- x should not have nil as a possible type here. In my live code this gives a "need-nil-check" warning.
In my live code the incorrect nil being on the type causes the need-nil-check warnings. But in the test it doesn't despite the class structure being equivalent for some reason. However, when you hover on the variables at the commented points it does show the incorrect nil type listed.
I tried adding a ---@cast - nil to remove the nil state, but then it didn't get added back after I set x = nil again in the if block. And when I used a ---@cast + nil there to try and correct this it cancelled out the - nil done earlier.
While trying to reproduce this outside of my code I found with a much simplier data structure the issue didn't occur, so nt sure if its caused by the nested classes confusing it somehow.
The text was updated successfully, but these errors were encountered:
I have found that in a specific case the nil type isn't being correctly removed and re-added to a variables type list.
See the comments below in an abstracted example of the issue:
In my live code the incorrect nil being on the type causes the need-nil-check warnings. But in the test it doesn't despite the class structure being equivalent for some reason. However, when you hover on the variables at the commented points it does show the incorrect nil type listed.
I tried adding a
---@cast - nil
to remove the nil state, but then it didn't get added back after I setx = nil
again in the if block. And when I used a---@cast + nil
there to try and correct this it cancelled out the- nil
done earlier.While trying to reproduce this outside of my code I found with a much simplier data structure the issue didn't occur, so nt sure if its caused by the nested classes confusing it somehow.
The text was updated successfully, but these errors were encountered: