Skip to content

Commit 403f11d

Browse files
authored
Fix js ouput of bigint max, min (#7088)
* fix js ouput of bigint max, min * add tests * changelog * use bigint_comp
1 parent 1de5e7c commit 403f11d

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- Fix tuple coercion. https://github.com/rescript-lang/rescript-compiler/pull/7024
3131
- Fix attribute printing. https://github.com/rescript-lang/rescript-compiler/pull/7025
3232
- Fix "rescript format" with many files. https://github.com/rescript-lang/rescript-compiler/pull/7081
33+
- Fix bigint max, min https://github.com/rescript-lang/rescript-compiler/pull/7088
3334

3435
#### :nail_care: Polish
3536

jscomp/core/lam_compile_primitive.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,14 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
411411
match args with
412412
| [ { expression_desc = Number (BigInt _) } as a; { expression_desc = Number (BigInt _) } as b ]
413413
when Js_analyzer.is_okay_to_duplicate a && Js_analyzer.is_okay_to_duplicate b ->
414-
E.econd (E.js_comp Clt a b) a b
414+
E.econd (E.bigint_comp Clt a b) a b
415415
| [ a; b ] -> E.runtime_call Primitive_modules.bigint "min" args
416416
| _ -> assert false)
417417
| Pbigintmax -> (
418418
match args with
419-
| [ { expression_desc = Number (Float _) } as a; { expression_desc = Number (Float _) } as b ]
419+
| [ { expression_desc = Number (BigInt _) } as a; { expression_desc = Number (BigInt _) } as b ]
420420
when Js_analyzer.is_okay_to_duplicate a && Js_analyzer.is_okay_to_duplicate b ->
421-
E.econd (E.js_comp Cgt a b) a b
421+
E.econd (E.bigint_comp Cgt a b) a b
422422
| [ a; b ] -> E.runtime_call Primitive_modules.bigint "max" args
423423
| _ -> assert false)
424424
| Pstringorder -> (

jscomp/core/lam_convert.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
305305
| Pasrbigint -> prim ~primitive:Pasrbigint ~args loc
306306
| Pbigintcomp x -> prim ~primitive:(Pbigintcomp x) ~args loc
307307
| Pbigintorder -> prim ~primitive:Pbigintorder ~args loc
308-
| Pbigintmin -> prim ~primitive:Pbigintorder ~args loc
309-
| Pbigintmax -> prim ~primitive:Pbigintorder ~args loc
308+
| Pbigintmin -> prim ~primitive:Pbigintmin ~args loc
309+
| Pbigintmax -> prim ~primitive:Pbigintmax ~args loc
310310
| Pintcomp x -> prim ~primitive:(Pintcomp x) ~args loc
311311
| Poffsetint x -> prim ~primitive:(Poffsetint x) ~args loc
312312
| Poffsetref x -> prim ~primitive:(Poffsetref x) ~args loc

tests/tests/src/bigint_test.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/tests/src/bigint_test.res

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ let () = {
164164
eq(__LOC__, bigint_asr(9n, -1n), 18n)
165165
eq(__LOC__, bigint_asr(-9n, 1n), -5n)
166166
eq(__LOC__, bigint_asr(-9n, -1n), -18n)
167+
eq(__LOC__, max(9n, 1n), 9n)
168+
eq(__LOC__, min(9n, 1n), 1n)
167169
}
168170

169171
let () = Mt.from_pair_suites(__MODULE__, suites.contents)

0 commit comments

Comments
 (0)