haxe icon indicating copy to clipboard operation
haxe copied to clipboard

"Implicit cast from I64 to Int (32 bits) is deprecated" has a wrong position with inline functions.

Open Speedphoenix opened this issue 1 year ago • 4 comments

In this snippet: (try haxe)

inline function pos(): hl.I64 {
	return 0;
}
inline function getAt(ret: hl.I64, pos: Int): hl.I64 {
	return pos;
}

inline function flipX(v: hl.I64) {
	var ret: hl.I64 = 0;
	ret += getAt(v, pos());
	return ret;
}
var sing: hl.I64 = 5;
var flipedx = flipX(sing);

You get the warning Implicit cast from I64 to Int (32 bits) is deprecated. Use .toInt() or explicitly cast instead. on the flipX(sing) call. Removing the inline on flipX, you get it on the getAt(v, pos()) call instead (which makes more sense since getAt takes an Int as second argument but pos returns hl.I64)

Speedphoenix avatar Apr 18 '25 10:04 Speedphoenix

Also in this situation

var v: hl.I64 = 4;
trace(v != 2); // implicit cast deprecated
trace(2 != v); // no warning

you get the Implicit cast is deprecated on the first trace but not the second. I kinda think the first trace should cast the Int on the right rather than the I64 on the left

Speedphoenix avatar Apr 18 '25 10:04 Speedphoenix

Hmm... if you have both a from Int and a deprecated @:to Int then I expect one of these versions to hit the deprecation warning. That seems to be more of a problem with the design of I64 itself.

However, I agree with you that this seems backwards: If the rhs can be cast to the lhs than that's what I expect to happen in both cases.

Simn avatar Apr 19 '25 03:04 Simn

As for the original issue, I'm actually seeing both positions:

 WARNING  source/Main.hx:11: characters 18-23

 11 |  ret += getAt(v, pos());
    |                  ^^^^^
    | (WDeprecated) Implicit cast from I64 to Int (32 bits) is deprecated. Use .toInt() or explicitly cast instead.

 WARNING  source/Main.hx:17: characters 31-42

 17 |  var flipedx = @:debug.inline flipX(sing);
    |                               ^^^^^^^^^^^
    | (WDeprecated) Implicit cast from I64 to Int (32 bits) is deprecated. Use .toInt() or explicitly cast instead.

Do you really only get one?

Simn avatar Apr 19 '25 03:04 Simn

Do you really only get one?

Yes, only one warning both with and without the inlines

$ haxe.exe test-haxe.hxml
 WARNING  Main.hx:155: characters 17-28

 155 |   var flipedx = flipX(sing);
     |                 ^^^^^^^^^^^
     | (WDeprecated) Implicit cast from I64 to Int (32 bits) is deprecated. Use .toInt() or explicitly
 cast instead.

Do note that I am not on the latest haxe (currently on 1249ed94463860fa515bae9c22e914b001b785d2)

I also get only one warning on try haxe

Image

Speedphoenix avatar Apr 23 '25 14:04 Speedphoenix