Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] add some Single test and [hl] fix null(f32) cannot cast to f64 #12041

Merged
merged 3 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/generators/genhl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1086,18 +1086,14 @@ let rec eval_to ctx e (t:ttype) =
let r = alloc_tmp ctx t in
op ctx (OFloat (r,alloc_float ctx (Int32.to_float i)));
r
(* this causes a bug with NG, to be reviewed later
| TConst (TInt i), HF32 ->
let r = alloc_tmp ctx t in
let bits = Int32.bits_of_float (Int32.to_float i) in
op ctx (OFloat (r,alloc_float ctx (Int64.float_of_bits (Int64.of_int32 bits))));
op ctx (OFloat (r, alloc_float ctx (Int32.to_float i)));
r
| TConst (TFloat f), HF32 ->
let r = alloc_tmp ctx t in
let bits = Int32.bits_of_float (float_of_string f) in
op ctx (OFloat (r,alloc_float ctx (Int64.float_of_bits (Int64.of_int32 bits))));
op ctx (OFloat (r, alloc_float ctx (float_of_string f)));
r
*)
| _ ->
let r = eval_expr ctx e in
cast_to ctx r t e.epos
Expand Down Expand Up @@ -1242,7 +1238,7 @@ and cast_to ?(force=false) ctx (r:reg) (t:ttype) p =
let r = alloc_tmp ctx (HNull t) in
op ctx (OToDyn (r,tmp));
r
| HNull ((HUI8 | HUI16 | HI32 | HI64) as it), (HF32 | HF64) ->
| HNull ((HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64) as it), (HF32 | HF64) ->
let i = alloc_tmp ctx it in
op ctx (OSafeCast (i,r));
let tmp = alloc_tmp ctx t in
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/src/unit/issues/Issue10965.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package unit.issues;

class Issue10965 extends Test {
#if jvm
#if (jvm || hl || cpp)
function testNeg() {
var a:Single = 1;
var c = -a;
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/src/unit/issues/Issue11647.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package unit.issues;

class Issue11647 extends Test {
#if (java || hl || cpp)
function test() {
foo();
}

function foo(a : Single = 10.0, b:Single = 11.0, c:Single = 12.0) : Void {
feq(10, a);
feq(11, b);
feq(12, c);
}
#end
}
47 changes: 47 additions & 0 deletions tests/unit/src/unit/issues/Issue12041.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package unit.issues;

class Issue12041 extends Test {
#if (java || hl || cpp)
@:analyzer(ignore)
function testCastNullFloat() {
var fnull : Null<Float> = null;
var snull : Null<Single> = null;
var f0 : Float = snull;
feq(f0, 0);
var s0 : Single = fnull;
feq(s0, 0);
}

@:analyzer(ignore)
function testSingleOp() {
var s1 : Single = 10.0;
feq(10.0, s1);
var s2 : Single = 0.3;
feq(0.3, s2);
var f1 : Float = 10.0;
var f2 : Float = 0.3;
var a : Single = s1 + s2;
feq(10.3, a);
var a : Single = s1 - s2;
feq(9.7, a);
var a : Single = s1 * s2;
feq(3.0, a);
var a : Single = s1 / s2;
feq(33.3333333333, a);
var a : Single = s1 / (f2 : Single);
feq(33.3333333333, a);
var a : Single = (f1 : Single) / s2;
feq(33.3333333333, a);
var a : Single = (f1 : Single) / (f2 : Single);
feq(33.3333333333, a);
}

@:analyzer(ignore)
function testSingleFromInt() {
var s1 : Single = 10;
feq(10.0, s1);
var s2 : Single = 3;
feq(3.0, s2);
}
#end
}
Loading