LuaLS / LuaLS/lua-language-server
No warning when assign constant `nil` to required table field
Open
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?
Linux
What is the issue affecting?
Type Checking
Expected Behaviour
Warning when assign constant nil to required table field
as it happens with ordinary variables
Actual Behaviour
Reproduction steps
---@type number
local n
n = nil
n = 1
---@class A
---@field n number
---@type A
local a = { n = nil }
a.n = 1
local NIL = nil
a.n = NIL
-- BUT no warning
a.n = nil -- ?
_ = { a, n }
Additional Notes
Most likely this is a duplicate but I couldn't find the issue
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
Start with the Lua reproduction in the issue and inspect the type-checking diagnostic path for table-field assignments. Confirm that assigning the constant nil to required field A.n produces the same warning as assigning nil to n; the existing cases and the final a.n = nil example define the expected behavior.
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
- Mostly clear
- Newbie friendliness
- 45/100