Skip to content

Assigning to class variable shadows inherited field #572

Open
@SylviBlossom

Description

@SylviBlossom
---@class A
---@field optional_num number|nil # Optional number
local a = {}

function a:set()
	self.optional_num = 1
end


--- @class B : A
local b = {}

function b:set()
	self.optional_num = 2
end


---@param v number # Non-nullable number
local function test_type(v) end


test_type(a.optional_num) -- Warning (expected behaviour, explicitly nullable)
test_type(b.optional_num) -- No warning (unexpected, should be the same as A)

Despite B extending A and assigning a matching value to the field, the field no longer has the type or comment annotation from A after any code sets it on B.

Additionally, code completion seems to behave strangely in this context:

Image

Image

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions