Haxe stub methods can't be overridden? Is the compiler inlining/optimizing them?

  • I've encountered a strange bug in Haxe 3.3.0 where methods can't be overridden if the parent class's method implementation is too simple:

    import flixel.FlxState;
    import flixel.text.FlxText;
    class MyState extends FlxState
     override public function create():Void {
      var item:Parent = new Child();
      var y:Int;
      var text:FlxText = new FlxText(0, 0, 0, "failure");
      y = item.updateText(text);
    private class Parent { 
     public function new() {
     public function updateText(text:FlxText):Int {
      return 0;
    private class Child extends Parent {
     override public function updateText(text:FlxText):Int {
      text.text = "success";
      return 1;

    I initialize a instance of "Child", and call "updateText". Since the child overrides updateText to modify the FlxText instance, we expect this to print a message of "success". However, this actually prints a message of "failure".

    Uncommenting the trace() statement fixes the bug, and allows the parent method to be overridden. Presumably the Haxe compiler sees that the method is doing something other than just returning a constant, and no longer inlines it. However since I don't want my game tracing every time updateText() is invoked, I've settled for adding this line to my code:

    for (i in []) trace("Haxe override workaround");

    I can insert this line into any Haxe method which needs to be overridden, but this seems a little silly. Is there some sort of compiler hint or keyword which can tell the Haxe compiler not to inline a method?

  • administrators

    This sounds like a compiler bug. I can actually reproduce it when I downgrade to Haxe 3.3.0-rc.1, but it works as expected in 3.4.0. -Dno-analyzer fixes it too, so it looks like this was a bug in the analyzer that's fixed by now.

    TL;DR: update Haxe. :)

  • Excellent, thanks for testing this out for me! I'll upgrade.

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.