intellij-haxe icon indicating copy to clipboard operation
intellij-haxe copied to clipboard

Typedef extending shows error.

Open barisyild opened this issue 1 year ago • 1 comments

Case 1

package ;

typedef TypedefInt = {
    var int:Int;
}

typedef TypedefFinal = {
    > TypedefInt;
}

class TestClass {
    public static function init() {
        var typedefFinal:TypedefFinal;
        trace(typedefFinal.int);
    }
}

image

Case 2

package ;

typedef TypedefInt = {
    var int:Int;
}

typedef TypedefFinal = {
    > TypedefInt,
}

class TestClass {
    public static function init() {
        var typedefFinal:TypedefFinal;
        trace(typedefFinal.int);
    }
}

image

Single typedef extending shows an error, but if you add a variable below it as in the image below, the problem disappears.

image

Case 3

package ;

typedef TypedefInt = {
    var int:Int;
}

typedef TypedefString = {
    var string:String;
}

typedef TypedefFinal = {
    > TypedefInt;
    var a:String;
    > TypedefString;
    var b:String;
}

class TestClass {
    public static function init() {
        var typedefFinal:TypedefFinal;
        trace(typedefFinal);
        trace(typedefFinal);
    }
}

image

However, if you extend more than one typedef as in the image, adding variables does not solve the problem.

barisyild avatar May 06 '24 12:05 barisyild

neither Case 1 nor Case 3 seems to be valid Haxe code when trying to compile it with try.haxe.org

Case 1 is incorrect because you should not use ; the fact that it removes the error highlighting when ; is added is probably just a bug, it should be , Case 2 while strange code (typdef extending without adding anything) compiles fine so the parser might need some tweaks. Case 3 will not work, all extends must be before any new members are added as far as i know.

i would recommend using the Haxe 4 syntax unless you need to target to target 3.x https://haxe.org/manual/types-structure-extensions.html

m0rkeulv avatar May 06 '24 14:05 m0rkeulv