Skip to content

Missing fields on inherited class not resulting in diagnostics warnings #2598

@b0o

Description

@b0o

How are you using the lua-language-server?

NeoVim

Which OS are you using?

Linux

What is the issue affecting?

Annotations, Type Checking, Diagnostics/Syntax Checking

Expected Behaviour

Should be a type error to not include all required fields from both parent and child class.

Actual Behaviour

Only fields from the child class are required.

With an empty table, we get a warning about missing the fields from the child class:

2024-04-05_06-15-08_region

When we fill in those fields, we get no warnings, even though the fields from the parent class are still missing:

2024-04-05_06-15-18_region

If we explicitly assign nil, we do get warnings:

2024-04-05_06-30-41_region

Reproduction steps

Check the diagnostics for the following snippets:

---@class Parent
---@field a string
---@field b string

---@class Child : Parent
---@field c string
---@field d string

---@type Child
local my_child = {} -- We get a warning here saying `c` and `d` are missing
---@class Parent
---@field a string
---@field b string

---@class Child : Parent
---@field c string
---@field d string

---@type Child
local my_child = {
  c = 'c',
  d = 'd',
} -- but no diagnostics here, even though `a` and `b` are missing

Additional Notes

No response

Log File

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions