Skip to content

Inherited field loses type when reassigned in child class #3127

@LnxFCA

Description

@LnxFCA

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, Diagnostics/Syntax Checking

Expected Behaviour

---@class TArg
---@field x number
---@field y number

---@class Parent
---@field T TArg

---@class Child : Parent
Child = {}

function Child:init()
    self.T = { y = 1, w = 1}  --- Expect type warning
end

print(Child.T) -- Expect T to be TArg but got `table`
  • LuaLS should warn that { y = 1, w = 1 } does not match TArg (since w is not defined).
  • Child.T should retain its inherited type (TArg), not become table.

Actual Behaviour

  • LuaLS does not warn about the incorrect structure.
  • T in Child is now treated as unknown or table, instead of TArg.

Reproduction steps

  • Paste the code snippet on any editor and check the types

Additional Notes

Possible workarounds

  • Manually redeclaring T in Child
---@class Child : Parent
---@field T TArg

This issue is particularly problematic in large projects where inheritance is heavily used. Manually re-declaring every inherited field just because it gets reassigned is redundant and error-prone.

Log File

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions