Skip to content

Do not shadow/re-inject fields in child-classes #2573

@Luke100000

Description

@Luke100000

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?

Diagnostics/Syntax Checking

Expected Behaviour

When assigning to a field which is already defined in one of it's supers, no injection should be used.

Actual Behaviour

Assigning to existing field is not possible as I effectively end up with two fields A.test and B.test.

The only valid workaround I know would be using setters in A.

Just disabling (exact) does not solve the issue, just disable the warning.

Reproduction steps

---@class (exact) A
---@field test number
local a = {}

function a:init()
    --This is fine
    self.test = 0
end

---@class (exact) B : A
local b = {}

function b:init()
    --This is an injection and thus invalid
    self.test = 0
end

Additional Notes

If shadowing a field is explicitly wanted, one can still define/type explicitly. But I think by default, no additional field should get injected.

Issue is a bit related to @override (#2569).

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