HaxeFoundation / HaxeFoundation/haxe
Missing a cast to abstract type for nested fields of object declaration
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
In the following code i expect `{field:'world'}` to be also casted to `Struct`:
```haxe
class Test {
static function main() {
check({ nested: {field:'world'} }); //first case: no implicit cast for {field:'world'} is generated
check(get());
}
static function check(o:Struct) {}
static function get():Options {
return { nested: {field:'world'} }; //second case: implicit cast is generated
}
}
abstract Struct(String) from String to String {
@:from
static public function fromObject(v:T):Struct return Std.string(v);
}
typedef Options = {?nested: Struct<{?field:String}>} //also if i make `nested` a mandatory field it does not even compile
```
But compiler does not generate implicit cast for the first case. Here is dump=pretty:
```haxe
@:directlyUsed @:used
class Test {
@:keep
static function main() {
Test.check(@:implicitCast _Test.Struct_Impl_.fromObject({nested : {field : "world"}}));
Test.check(@:implicitCast _Test.Struct_Impl_.fromObject(Test.get()));
}
static function check(o:Struct) {}
static function get() {
return {nested : @:implicitCast _Test.Struct_Impl_.fromObject({field : "world"})};
}
}
```
Here is [try.haxe](http://try.haxe.org/#BA576) (check generated js)
Contributor guide
Assessment
This issue has not been assessed yet.