wurstscript / WurstScript

Programming language and toolkit to create Warcraft III Maps
https://wurstlang.org
Apache License 2.0
226 stars 28 forks source link

Null references not correctly migrated from compiletime to runtime in lua #994

Closed Jampi0n closed 3 years ago

Jampi0n commented 3 years ago

Describe the bug If an object is created at compiletime and it contains a null reference, the initCompiletimeState function will save the null reference as an integer.

Here is an example:

package Hello

import NoWurst
import public _Handles // map does not load without this import. error in generated lua script?
import public MagicFunctions

function print(string msg)
    DisplayTimedTextToPlayer(GetLocalPlayer(), 0., 0., 45., msg)

class A
    function foo()
        print("I am A")

class B
    A a = null

function createB() returns B
    return new B()

constant b = compiletime(createB())

init
    if b.a == null
        b.a = new A()
    b.a.foo()

The init part will not work, because b.a == null returns false (b.a = 0), so no new object is created and foo cannot be called on an integer.

Frotty commented 3 years ago

the lua backend isn't finished, thanks for the report

Frotty commented 3 years ago

is this fixed?

Jampi0n commented 3 years ago

yes, it is.