-
-
Notifications
You must be signed in to change notification settings - Fork 391
Closed
Description
How are you using the lua-language-server?
NeoVim
Which OS are you using?
Linux
What is the issue affecting?
Type Checking
Expected Behaviour
Accept tbl.foo = bar where tbl's keys are typed to a different type than __newindex's value type.
Actual Behaviour
Get error because bar's type is different from tbl's keys type.
Reproduction steps
With this initial code:
---@class PlugTagSpec
---@field name string
---@field desc string
---@type {[string]: PlugTagSpec}
local predefined_tags = setmetatable({}, {
---@param name string
---@param spec {name?: string, desc: string}
__newindex = function(self, name, spec)
spec.name = name -- add name in spec
rawset(self, name, spec)
end,
})Use it with:
predefined_tags.foo = { desc = "bar" }π Get error:
Missing required fields in type `PlugTagSpec`: `name`.. even though
__newindexexplicitely does not require the value to be a full spec but only its description (desc).
Additional Notes
Related: #2941
Log File
No response
Metadata
Metadata
Assignees
Labels
No labels