haxe icon indicating copy to clipboard operation
haxe copied to clipboard

[jvm] Rest Array Comprehension cannot cast to class

Open PXshadow opened this issue 3 years ago • 2 comments

import haxe.Rest;

function main() {
    test(0,1); // works
    test(...[0,1]); // works
    test(...[for (i in 0...2) i]); // errors
}

function test(args:Rest<Int>) {}
Exception in thread "main" java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class [Ljava.lang.Integer; ([Ljava.lang.Object; and [Ljava.lang.Integer; are in module java.base of loader 'bootstrap')
        at _Main.Main_Fields_.main(Main.hx:7)
        at _Main.Main_Fields_.main(Main.hx:1)

Haxe version: 4.3.0-rc.1

PXshadow avatar Jul 21 '22 04:07 PXshadow

import haxe.Rest;

function main() {
	var a = {
		var tmp = [];
		tmp.push(0);
		tmp;
	};
	test(...a);
}

function test(args:Rest<Int>) {
	trace(args);
}

The dump has this:

[Unop:haxe.Rest<Int>]
	...
	Prefix
	[Meta:haxe.Rest<Int>]
		:implicitCast
		[Call:haxe.Rest<Int>]
			[Field:(array : Array<Unknown<1>>) -> haxe.Rest<Unknown<1>>]
				[TypeExpr haxe._Rest.Rest_Impl_:{ Statics haxe._Rest.Rest_Impl_ }]
				[FStatic:(array : Array<Unknown<1>>) -> haxe.Rest<Unknown<1>>]
					haxe._Rest.Rest_Impl_
					of:(array : Array<of.T>) -> haxe.Rest<of.T>
			[Local a(3260):Array<Int>:Array<Int>]

I don't think there should be any monomorphs here, but I'll have to check where that of call even comes from.

Simn avatar Jul 26 '22 09:07 Simn

Ah right, this is just a @:from function from Array<T> to Rest<T>. But this still doesn't explain why there's a monomorph here because this is quite clearly an Array<Int>.

Simn avatar Jul 26 '22 09:07 Simn