haxe
haxe copied to clipboard
Std.int in abstract
package;
class Main
{
static function main()
{
trace((1.5555:R));
}
}
abstract R(Float) to Float {
private inline function new(v:Float)
this = Std.int(v);
@:from
public static inline function fromFloat(v:Float):R
return new R(v);
}
1 is expected, but got 1.5555 on java & cs @ 7230d00
This is regression, it worked in 3.2.1
@waneck: I think this one is yours because the dump looks fine to me:
[Call:Void]
[Field:v : Dynamic -> ?infos : Null<haxe.PosInfos> -> Void]
[TypeExpr haxe.Log:Class<haxe.Log>]
[FStatic:v : Dynamic -> ?infos : Null<haxe.PosInfos> -> Void]
haxe.Log
trace
[Cast:R]
[Meta:R]
:implicitCast
[Cast:R] [Const:Float] 1.5555
[ObjectDecl:{ methodName : String, lineNumber : Int, fileName : String, className : String }]
fileName: [Const:String] "Main.hx"
lineNumber: [Const:Int] 7
className: [Const:String] "Main"
methodName: [Const:String] "main"
Generated Java:
haxe.Log.trace.__hx_invoke2_o(((double) (1.5555) ), haxe.lang.Runtime.undefined, 0.0, new haxe.lang.DynamicObject(new java.lang.String[]{"className", "fileName", "methodName"}, new java.lang.Object[]{"Main", "Main.hx", "main"}, new java.lang.String[]{"lineNumber"}, new double[]{((double) (((double) (7) )) )}));
This requires attention for the RC, I can't make a release with this being broken...
as talked with @Simn, the problem is with the analyzer/inliner which changes the cast to R instead of Int. However, I've added a workaround which fixes the issue on java/c# anyway. Performance should be the same, since they are transformed into Std.int later
The good news is that this is not a general inlining problem and indeed comes from the analyzer, namely const propagation. The bad news is that I get some failing tests in other places after fixing it. Gonna have to investigate this further.
This is too hard for me to get right for 3.3 and since the regression has been addressed I'll move it to 3.4.
package;
class Main
{
static function main() {
run((1.5555:R));
}
static public inline function int(v:Float):Int {
return cast v;
}
static dynamic function run(t:Dynamic) {
trace(t);
}
}
abstract R(Float) to Float {
private inline function new(v:Float)
this = Main.int(v);
@:from
public static inline function fromFloat(v:Float):R
return new R(v);
}
This works without analyzer. Analyzer removes a cast to int. Without analyzer:
[Block:Void]
[Var this1(3610):Float] [Cast:Int] [Const:Float] 1.5555 // here is the cast
[Call:Void]
[Field:(t : Dynamic) -> Void]
[TypeExpr Main:Class<Main>]
[FStatic:(t : Dynamic) -> Void]
Main
run:(t : Dynamic) -> Void
[Meta:R]
:implicitCast
[Cast:R] [Local this1(3610):Float:Float]
With analyzer
[Block:Void]
[Call:Void]
[Field:(t : Dynamic) -> Void]
[TypeExpr Main:Class<Main>]
[FStatic:(t : Dynamic) -> Void]
Main
run:(t : Dynamic) -> Void
[Meta:R]
:implicitCast
[Cast:R] [Const:Float] 1.5555 // it's gone
Actually it's broken for all static targets (cpp & hl too)
Working fine in 4.1.2
I can still reproduce it using this sample with Haxe 4.1.2 and the latest dev Haxe
Problem only for static targets when using cast instead of Std.int, i updated unit test: Issue5124.txt