You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
constructor is dependent on load order, and works extremely inconsistently #1007
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:
localMyClass=class("MyClass") -- class uses the constructor attribute properlyreturnMyClass
--- different filelocalmyInstance=MyClass() -- WARNING: Cannot call expression of type `EditorDockTree`
and:
---@classMyOtherClass---@field__instanceMyClasslocalMyOtherClass=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.
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.
This is an issue with the order of analysis. When I designed it, I never considered declaring meta as a global function, so the current order makes sense to me. Fixing this would take a great deal of effort, and it isn’t where my development focus lies.
I recommend declaring it as a local function and then require-ing it.
MyInheritedClass will say "Cannot call expression of type MyInheritedClass.", as it inherits the init function from MyClass. Adding an explicit init function to MyInheritedClass does fix this, but this is not desirable behavior to have useless functions like that, in my opinion.
Activity
xuhuanzy commentedon Apr 3, 2026
This is an issue with the order of analysis. When I designed it, I never considered declaring
metaas a global function, so the current order makes sense to me. Fixing this would take a great deal of effort, and it isn’t where my development focus lies.I recommend declaring it as a local function and then
require-ing it.fix: EmmyLuaLs#1007
xuhuanzy commentedon Apr 5, 2026
Since the next release may come quite a bit later, you can pull #1017 and build it yourself to fix this issue.
NyakoFox commentedon Apr 6, 2026
Testing it, I have noticed the following things:
nilunlessreturn_modeis set to"self"; meaning"default"does not properly "fall back" to"self"I think."self", it does work for most cases!MyInheritedClasswill say "Cannot call expression of typeMyInheritedClass.", as it inherits theinitfunction fromMyClass. Adding an explicitinitfunction toMyInheritedClassdoes fix this, but this is not desirable behavior to have useless functions like that, in my opinion.xuhuanzy commentedon Apr 6, 2026
Example
NyakoFox commentedon Apr 6, 2026
The error seems to come from
inithaving content, for example a print:Code_-_Insiders_VkM10Lli3Z.mp4
MRE: mre.zip
xuhuanzy commentedon Apr 6, 2026