haxe
haxe copied to clipboard
[bug/qol?] abstract over map instantiated with `[]` gets typed to an array
class Test {
static function main() {
var map:Foo = [];
}
}
abstract Foo(Map<String, Int>) from Map<String, Int> {
public function new(value:Map<String, Int> = null) {
this = value ?? [];
}
}
https://try.haxe.org/#4844a077 This fails to compile however the below works fine
var map:Map<String, Int> = []
Workaround for empty array literal: https://try.haxe.org/#229CCBDE
@:from static macro function fromEmptyArray(e) {
return switch haxe.macro.Context.typeExpr(e).expr {
case TArrayDecl([]): macro new Foo();
case _: e;
}
}
Note that it won't handle this:
var a = [];
var map:Foo = a;