haxe
haxe copied to clipboard
Mono to Any cast error
class Main {
static function main() {
final data = ({} : Dynamic);
data.id = 0;
test(data); // Any should be { id : Int }
}
static function test(v:Any) {
trace(v);
}
}
No error in 4.2.5
This is pretty stupid. When unifying a type with a constrained monomorph, the compiler checks if the type fulfills the contraints, so it tries to assign it to each constraint. That's why the unification error is in that direction.
The silly part is that Any has from Dynamic, but it never comes into play due to the inverse direction of the unification.
I don't think I'll be able to address this for 4.3.
Actually, this is a catastrophe:
class C {
public var id:Int;
}
class Main {
static function main() {
final data = ({} : Dynamic);
data.id = 0;
test(data); // Don't know how to cast dynobj to C
}
static function test(v:C) {
trace(v);
}
}
Bisecting your example brought me to https://github.com/HaxeFoundation/haxe/commit/eda6551f2b4fa3f0b80088eb39869d1b83f811d7, which makes this problem even more ridiculous. It's kind of good news because it means that the regression is strictly related to Any itself.
My example is already a type hole on 4.2.5, so this isn't as urgent as I thought. I might look into this for 4.3.1 instead.
Should we try to get this fixed on 4.3.4? :sweat_smile:
No
I see this issue has more than 2 years, do you know maybe when approximatively it could be fixed please ?
Roughly in two years from now.