Skip to content

[Bug]: Valid checks don't suppress undefined-global #2

@Pollux12

Description

@Pollux12

Area

Language server

What happened?

Valid checks (such as IsValid) do not correctly suppress undefined-global for the rest of that scope. The expected result is that we should be narrowing the type to be any (depends on the check) even if undefined before for the rest of that scope, since if it was actually invalid, the code scoped within the valid check would not run.

How can it be reproduced?

undefined-global diagnostic should not occur in these examples:

local function TestFunction()
	if not testVar then return end 
	if not testVar.Field then return end -- diagnostic on testVar: undefined global variable: testVar GLuaLS(undefined-global)
	print(testVar) -- diagnostic on testVar: undefined global variable: testVar GLuaLS(undefined-global)
end
local function TestFunction2()
    if not istable(testVar2) then return end -- testVar2 = any
    if not testVar2.TestField then return end -- testVar2 = table but still giving undefined-global diagnostic
    print(testVar2.TestField) -- testVar2 = table and field TestField = any but still giving undefined-global diagnostic
end

Additional info

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinglanguage-serverLanguage server issues

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions