Skip to content

Commit f7af484

Browse files
Fix Parmatch crash on empty record head patterns
1 parent e55c5e4 commit f7af484

5 files changed

Lines changed: 81 additions & 1 deletion

File tree

compiler/ml/parmatch.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ let extract_fields omegas arg =
512512

513513
let all_record_args lbls =
514514
match lbls with
515+
| [] -> []
515516
| (_, {lbl_all}, _, opt) :: _ ->
516517
let t =
517518
Array.map
@@ -560,7 +561,6 @@ let all_record_args lbls =
560561
t.(lbl.lbl_pos) <- x)
561562
lbls;
562563
Array.to_list t
563-
| _ -> fatal_error "Parmatch.all_record_args"
564564

565565
(* Build argument list when p2 >= p1, where p1 is a simple pattern *)
566566
let rec simple_match_args p1 p2 =
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @ts-check
2+
3+
import { setup } from "#dev/process";
4+
5+
const { execBuild } = setup(import.meta.dirname);
6+
7+
await execBuild();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "parmatch_empty_record_pattern",
3+
"sources": ["src"],
4+
"dependencies": []
5+
}

tests/build_tests/parmatch_empty_record_pattern/src/repro.js

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
type method_ = Post | Get
2+
3+
type body = Json(JSON.t)
4+
5+
type request = {
6+
method: method_,
7+
url: string,
8+
headers: dict<string>,
9+
body: body,
10+
}
11+
12+
let classify = request =>
13+
switch request {
14+
| {
15+
method: Post,
16+
url,
17+
headers: dict{"Authorization": "Token"},
18+
body: Json(JSON.Object(dict{
19+
"request": JSON.String("READ"),
20+
"payload": JSON.Object(dict{
21+
"list-a": JSON.Object(dict{"last_known_events": JSON.Object(dict{})}),
22+
}),
23+
})),
24+
} if url->String.includes("/todo/events") =>
25+
1
26+
| _ => 0
27+
}

0 commit comments

Comments
 (0)