Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
> - :nail_care: [Polish]
> - :house: [Internal]

# 12.3.2 (Unreleased)

#### :bug: Bug fix

- Fix integer range patterns, including nested record and exception patterns, incorrectly matching values below the range. https://github.com/rescript-lang/rescript/pull/8714

# 12.3.1

#### :bug: Bug fix
Expand Down
2 changes: 1 addition & 1 deletion compiler/core/js_exp_make.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ let rec is_out ?comment (e : t) (range : t) : t =
{expression_desc = Number (Int {i = 0l}); _} ) ) ->
(* TODO: check correctness *)
is_out ?comment e range
| _, _ -> int_comp ?comment Cgt e range
| _, _ -> int_comp ?comment Cgt (int32_lsr e zero_int_literal) range

let rec float_add ?comment (e1 : t) (e2 : t) =
match (e1.expression_desc, e2.expression_desc) with
Expand Down
35 changes: 35 additions & 0 deletions tests/tests/src/or_pattern_int_range_test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Mocha from "mocha";
import * as Test_utils from "./test_utils.mjs";

function isRetriable(error) {
return (error.status - 502 >>> 0) <= 2;
}

Mocha.describe("Or_pattern_int_range_test", () => {
Mocha.test("int range on record field", () => Test_utils.eq("File \"or_pattern_int_range_test.res\", line 15, characters 6-13", [
404,
500,
501,
502,
503,
504,
505
].map(status => isRetriable({
status: status
})), [
false,
false,
false,
true,
true,
true,
false
]));
});

export {
isRetriable,
}
/* Not a pure module */
20 changes: 20 additions & 0 deletions tests/tests/src/or_pattern_int_range_test.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
open Mocha
open Test_utils

type response = {status: int}

let isRetriable = error =>
switch error {
| {status: 502 | 503 | 504} => true
| _ => false
}

describe(__MODULE__, () => {
test("int range on record field", () => {
eq(
__LOC__,
[404, 500, 501, 502, 503, 504, 505]->Array.map(status => isRetriable({status: status})),
[false, false, false, true, true, true, false],
)
})
})
Loading