Skip to content

Commit 615cf8f

Browse files
authored
Allow coercing int to float (#6448)
* allow coercing int to float * changelog
1 parent ab39e10 commit 615cf8f

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#### :rocket: New Feature
1616
- Allow coercing unboxed variants with only strings (now including with a single payload of string) to the primitive string. https://github.com/rescript-lang/rescript-compiler/pull/6441
1717
- Allow coercing strings to unboxed variants that has a catch-all unboxed string case. https://github.com/rescript-lang/rescript-compiler/pull/6443
18+
- Allow coercing `int` to `float`. https://github.com/rescript-lang/rescript-compiler/pull/6448
1819

1920
#### :bug: Bug Fix
2021

jscomp/ml/ctype.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3951,6 +3951,8 @@ let rec subtype_rec env trace t1 t2 cstrs =
39513951
end
39523952
| (Tconstr(p1, _, _), _) when generic_private_abbrev env p1 ->
39533953
subtype_rec env trace (expand_abbrev_opt env t1) t2 cstrs
3954+
| (Tconstr(p1, [], _), Tconstr(p2, [], _)) when Path.same p1 Predef.path_int && Path.same p2 Predef.path_float ->
3955+
cstrs
39543956
| (Tconstr(path, [], _), Tconstr(_, [], _)) when Path.same path Predef.path_string &&
39553957
extract_concrete_typedecl env t2 |> Variant_coercion.can_try_coerce_variant_to_primitive |> Option.is_some
39563958
->

jscomp/test/Coercion.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/Coercion.res

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let x = 1
2+
3+
let xx = (x :> float)

jscomp/test/build.ninja

Lines changed: 2 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)