lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Accessing deeply nested variable at 'if' statemet cause type collision

Open TriRozhka opened this issue 1 year ago • 6 comments

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

Type checking does not breaks after accessing variable at 'if' statement.

Actual Behaviour

2nd nested variable type became '<type> | unknown' so accessing variable or function which not exists in this class does not cause warning.

Reproduction steps

---@class DemoD
---@field c integer 
local DemoD = {}
DemoD.c = 0

---@class DemoC
local DemoC = {}
DemoC.D = DemoD

---@class DemoB
local DemoB = {}
DemoB.C = DemoC

---@class DemoA
local DemoA = {}
DemoA.B = DemoB

---@class DemoRoot
DemoRoot = {}
DemoRoot.A = DemoA

local d = DemoRoot.A.B.C.D

-- if d.c > 1 then end -- if we replace 'DemoRoot.A.B.C.D' with 'd' then F is undefined in all 4 cases
if DemoRoot.A.B.C.D.c > 1 then end

DemoRoot.F() -- warning: F is undefined
DemoRoot.A.F() -- warning: F  is undefined
DemoRoot.A.B.F() -- no warning
DemoRoot.A.B.C.F() -- no warning

if-statement-bug

Additional Notes

No response

Log File

No response

TriRozhka avatar Jun 21 '24 22:06 TriRozhka