HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.03k stars 648 forks source link

@:structInit ambiguity when @:from between abstract forwarded types #11586

Open nspitko opened 4 months ago

nspitko commented 4 months ago

Oh god I hope this title makes sense.

This is a followup to #11535, it seems I cut down my repro a bit too much to expose all the fun exciting quirks.

The fix for the previous issue works fine for direct classes, but breaks when pointing through abstracts, as below. The only change from the previous repro is that we're now coming @:from the Bar abstract instead of BarImpl directly.

Tested against haxe nightly 6ab9980d461f9994a6ceb203a3ded05587d2e901

Repro:

// Bar 
// Removing this @:structInit will fix the build.
@:structInit
class BarImpl {
    public function new() {}
}

@:forward
abstract Bar(BarImpl) from BarImpl to BarImpl {
}

// FooImpl
@:structInit
class FooImpl {
    public var x:Float;

    public function new(x:Float) {
        this.x = x;
    }
}

// Foo
@:forward
abstract Foo(FooImpl) from FooImpl to FooImpl {
    public function new(x:Float) {
        this = new FooImpl(x);
    }

    @:from
    static public function fromBar(v:Bar):Foo {
        return new Foo(1);
    }

}

// Main
class Test {
    static function main() {
        var v:Foo = {x: 2};
        trace(v.x);
    }
}

try.haxe: https://try.haxe.org/#54AAA5cC

nanjizal commented 4 months ago
var v:Foo = ({x:2}:FooImpl);