HaxeFoundation / HaxeFoundation/haxe
Issue with inline + multi multitype
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
A multityped abstract over a multityped abstract over an interface provides unexpected behavior if the outermost abstract has inlined `@:to` converters. `inline` or not in the inner abstract's `@:to` does not appear to matter.
Explanation of code: `new A()` should result in a `C` being created, tracing out "C". `new A()` should result in `D` and "D". Because the string path's `@:to` is inlined, it seems like a `B` is being created and used instead of a `D` even though `B` is abstract.
Note: if `A,B,C,D` have a parameter in their constructors, `new A("param")` will cause a runtime error for too many arguments. However, deleting the argument leads to a compile time error for not enough arguments, which is expected.
```haxe
class Test {
static function main() {
// should trace "C"
trace(new A()); // "C"
// should trace "D"
trace(new A()); // "[object B_Impl_]", issues with double inlined @:to
}
}
@:multiType(T)
@:forward
abstract A(B) {
public function new();
@:to static function aToC(b:B):B { return new B(); }
@:to static inline function aToD(b:B):B { return new B(); }
}
@:multiType(T)
@:forward
abstract B(I) {
public function new();
@:to static function bToC(c:I):C { return new C(); }
@:to static function bToD(d:I):D { return new D(); }
}
class C implements I {
public function new() { }
public function toString():String { return 'C'; }
}
class D implements I {
public function new() { }
public function toString():String { return 'D'; }
}
interface I {
function toString():String;
}
```
(sorry if there's a more minimal example)
Relevant js output:
```js
Test.main = function() {
console.log(_$Test_A_$Impl_$.aToC(null));
console.log(new _$Test_B_$Impl_$());
};
var _$Test_A_$Impl_$ = {};
_$Test_A_$Impl_$.aToC = function(b) {
return _$Test_B_$Impl_$.bToC(null);
};
_$Test_A_$Impl_$.aToD = function(b) {
return _$Test_B_$Impl_$.bToD(null);
};
var _$Test_B_$Impl_$ = {};
_$Test_B_$Impl_$.bToC = function(c) {
return new C();
};
_$Test_B_$Impl_$.bToD = function(d) {
return new D();
};
```
Haxe 3.4.2 master and latest dev if I installed it properly
Contributor guide
Assessment
This issue has not been assessed yet.