wurstscript / WurstScript

Programming language and toolkit to create Warcraft III Maps

Home Page:https://wurstlang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Lua] Modules are not initialized in derived classes when the module is used in the base class

jlfarris91 opened this issue · comments

It looks like modules are not correctly initialized for derived classes where the module is used in the base class.

I have a base class TlsBuildingDefinition that uses a module called UnitDefinitionInitModule and a derived class called CannonTowerDefinition.

image

image

In the compiled lua you can see that the TlsBuildingDefinition create function initializes all the module fields, but the CannonTowerDefinition create function does not.

image

image

So, when constructing CannonTowerDefinition instance, all the module fields are nil and ultimately break a lot of dependent code.

Module init should only be for the class that uses it. If it's not inited for you then the issue in your case is not missing module init, but The CannonTower constructor not calling the super constructor and thus the module init correctly.
In your example the important code should be in the CannonTowerDefinition_construct_CannonTowerDefinition function, which you did not include.
I tried to reproduce this with a small example:

module M
    protected var mi = 1

interface I

class A
    var ai = 2

    use M

class B extends A implements I
    var bi = 3

class C extends B
    var ci = 4

init
    doAfter(0.7) ->
        let c = new C()
        print("b test")
        print(c.mi)
        print(c.ai)
        print(c.bi)
        print(c.ci)

But this works fine, the super constructor call is added.
@jlfarris91 If you still have this issue please post a complete, reproducible example.

Perhaps the issue in your case is simply trying to access the module's values, before they are inited?