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

Defining optional globals doesn't trigger nil check warning

Open emmericp opened this issue 1 year ago • 0 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

I have some code that runs in different environments that have different global variables available.

For example, environment1 may have a global table C_GameRules available with a function in it. environment2 does not have the global available.

I'm trying to write a meta file that makes this optional nature of this global available:

---@meta

---@type table?
C_GameRules = nil

---@return boolean
function C_GameRules.IsHardcoreActive() end

I've also tried to define a class, no change in behavior

Actual Behaviour

C_GameRules.IsHardcoreActive() does not trigger a need-nil-check warning, but the type of C_GameRules gets shown as table?

Reproduction steps

see above

Additional Notes

i don't want the inner field as nilable, environment 1 has "C_GameRules" as global available and the function is guaranteed to be in there, environment 2 has the global set to nil

Log File

No response

emmericp avatar Dec 15 '23 16:12 emmericp