Skip to content

constructor is dependent on load order, and works extremely inconsistently #1007

@NyakoFox

Description

@NyakoFox

With the 0.22.0 release, there are suddenly an extreme amount of warnings throughout our codebase which did not exist before; strange warnings such as:

local MyClass = class("MyClass") -- class uses the constructor attribute properly

return MyClass
--- different file
local myInstance = MyClass() -- WARNING: Cannot call expression of type `EditorDockTree`

and:

---@class MyOtherClass
---@field __instance MyClass
local MyOtherClass = class("MyOtherClass")

MyOtherClass.__instance = MyClass() -- WARNING: Cannot assign `self` to `MyClass`

They seem to be related to the order in which things are loaded by EmmyLua; Minimal reproducible examples are very hard for us to create as these issues are very ephemeral.

It seems like the problem occurs when the "constructor defining function" (what uses @[constructor()] is "loaded" after an actual call to it.

Nonetheless, attached are two MREs which solely differ in filename; one that always has the problem, and one that never has the problem.

warning.zip
no_warning.zip

Do note that, when testing, only the "main" file should be opened in your IDE; opening one of other two make the issue not occur.

Code_-_Insiders_Q9uvpUDt9Z.mp4

It does seem like these issues have existed since the "constructor" attribute was added, but warnings for "Cannot call expression" did not exist prior. This system has never worked consistently for us, which is frustrating when our project relies heavily on it. We have noticed that, before this update, the constructor attribute would refuse to work most of the time. It has just not triggered warnings until now.

Thank you.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions