haxe icon indicating copy to clipboard operation
haxe copied to clipboard

Mono to Any cast error

Open RblSb opened this issue 2 years ago • 7 comments

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

RblSb avatar Mar 31 '23 16:03 RblSb

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.

Simn avatar Mar 31 '23 16:03 Simn

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);
	}
}

Simn avatar Mar 31 '23 16:03 Simn

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.

Simn avatar Mar 31 '23 18:03 Simn

Should we try to get this fixed on 4.3.4? :sweat_smile:

kLabz avatar Feb 18 '24 16:02 kLabz

No

Simn avatar Feb 18 '24 16:02 Simn

I see this issue has more than 2 years, do you know maybe when approximatively it could be fixed please ?

filt3rek avatar Apr 11 '25 14:04 filt3rek

Roughly in two years from now.

Simn avatar Apr 11 '25 15:04 Simn