lua-language-server
                                
                                 lua-language-server copied to clipboard
                                
                                    lua-language-server copied to clipboard
                            
                            
                            
                        Casting an otherwise unused variable in a block preserves the cast outside of block
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
Any casts inside a block should not be maintained once leaving that block.
Actual Behaviour
Type cast is maintained even after the block in which the variable was cast if and only if the variable was not used in that block.
Reproduction steps
This is incorrect:
---@type number|string
local i
if true then --can be `false` or any other logical
  ---@cast i number
  local _ = 0 --not referencing variable `i` that was cast above
end
local j = i --type of j is `number`, should be `number|string`
This is correct:
---@type number|string
local i
if true then --can be `false` or any other logical
  ---@cast i number
  local _ = i -- referencing variable `i` that was cast above
end
local j = i --type of j is `number|string`
Additional Notes
No response
Log File
No response