HaxeFoundation / HaxeFoundation/haxe
macro @:from and array unification
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
Haxe 4.2.3
Given a type which is an array of object with optional fields, the compiler is able to unify ArrayDecl expressions with such type even if such optional fields are not present. But the same does not work in a @:from macro
```haxe
class Main {
#if !macro
static function main() {
var arr = ([{foo: 1}]:Array); // ok
var arr:A = [{foo: 1}]; // see ofExpr below
}
#end
}
abstract A(Int) {
@:from public static macro function ofExpr(e) {
trace(haxe.macro.Context.typeof(macro ($e:Array))); // error: { foo : Int } has no field bar
return macro throw 'irrelvant';
}
}
typedef Obj = {
final foo:Int;
final ?bar:Int;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.