LuaLS / LuaLS/lua-language-server
Missing "need-check-nil" on self fields
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, Diagnostics/Syntax Checking
Expected Behaviour
I expect both methods to report the "need check nil" diagnostic:
---@class Y
---@field z string
---@class X
---@field y Y?
local X = {}
function X:no_warning()
print(self.y.z) -- no diagnostics
end
function X:warning()
local y = self.y
print(y.z) -- need-check-nil
end
Actual Behaviour
The potential problem is only reported when using a local variable.
Reproduction steps
Try the code above. and note how only the first method (no_warning) works without any diagnostics.
Additional Notes
No response
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 issue in the Visual Studio Code extension using the Lua snippet in the report, and compare diagnostics for self.y.z with the local-variable case y.z. Trace the type-checking or diagnostic entry point responsible for nil checking; done means both methods report the need-check-nil diagnostic without changing the example's types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100