LuaLS / LuaLS/lua-language-server
Defining optional globals doesn't trigger nil check warning
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report in the Visual Studio Code Extension using the shown Lua meta-file declaration and inspect the type-checking diagnostics for C_GameRules.IsHardcoreActive(). Done means an optional global produces a nil-check warning while its inner function remains non-nilable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100