Skip to content

Commit b6b67ae

Browse files
authored
Allow Single div without cast to Float (#12039)
* [hl] Allow F32 div without cast to Float * unsigned_op is not needed in f32 div * Use Single in div result type when e1 and e2 are both Single * Only do is_single check if OpDiv * [tests] add Single type test and fix a out path * [tests] do not use -fail in hxml(.stderr)
1 parent 98b4326 commit b6b67ae

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

src/typing/operators.ml

+7-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,13 @@ let make_binop ctx op e1 e2 is_assign_op p =
305305
| KFloat, KFloat ->
306306
result := tfloat
307307
| KNumParam t1, KNumParam t2 when Type.type_iseq t1 t2 ->
308-
if op <> OpDiv then result := t1
308+
(match op with
309+
| OpDiv ->
310+
let is_single = (match follow e1.etype with TAbstract({a_path=[],"Single"},_) -> true | _ -> false) in
311+
if is_single then result := t1
312+
| _ ->
313+
result := t1
314+
)
309315
| KNumParam _, KNumParam _ ->
310316
result := tfloat
311317
| KNumParam t, KInt | KInt, KNumParam t ->
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
-m Issue11196
2-
-hl out.hl
2+
-hl out/main.hl
33
-dce no
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Main {
2+
static function main() {
3+
var s1 : Single = 10.0;
4+
var s2 : Single = 0.3;
5+
var f1 : Float = 10.0;
6+
var f2 : Float = 0.3;
7+
$type(s1 + s2);
8+
$type(s1 - s2);
9+
$type(s1 * s2);
10+
$type(s1 / s2);
11+
$type(s1 / (f2 : Single));
12+
$type((f1 : Single) / s2);
13+
$type((f1 : Single) / (f2 : Single));
14+
$type(f1 / s2);
15+
$type(s1 / f2);
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--main Main
2+
--hl out/main.hl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Main.hx:7: characters 9-16 : Warning : Single
2+
Main.hx:8: characters 9-16 : Warning : Single
3+
Main.hx:9: characters 9-16 : Warning : Single
4+
Main.hx:10: characters 9-16 : Warning : Single
5+
Main.hx:11: characters 9-27 : Warning : Single
6+
Main.hx:12: characters 9-27 : Warning : Single
7+
Main.hx:13: characters 9-38 : Warning : Single
8+
Main.hx:14: characters 9-16 : Warning : Float
9+
Main.hx:15: characters 9-16 : Warning : Float

0 commit comments

Comments
 (0)