Skip to content

Commit f54dbdf

Browse files
authored
feat(compiler): Improve exhaustive warning for lists (#2220)
1 parent d557923 commit f54dbdf

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

compiler/src/typed/printpat.re

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,29 @@ let rec pretty_val = (ppf, v) =>
9191
fprintf(ppf, "@[{%a%t}@]", pretty_lvals, filtered_lvs, elision_mark);
9292
};
9393
| TPatConstant(c) => fprintf(ppf, "%s", pretty_const(c))
94-
| TPatConstruct(_, cstr, args) =>
95-
if (List.length(args) > 0) {
96-
fprintf(ppf, "@[%s(%a)@]", cstr.cstr_name, pretty_vals(","), args);
94+
| TPatConstruct(_, {cstr_name}, args) =>
95+
if (cstr_name == "[...]") {
96+
fprintf(
97+
ppf,
98+
"@[[%a]@]",
99+
pretty_vals(","),
100+
List.rev(
101+
List.fold_left(
102+
(acc, arg) =>
103+
switch (arg.pat_desc) {
104+
| TPatConstruct(_, {cstr_name: "[...]"}, args) =>
105+
List.concat([args, acc])
106+
| _ => [arg, ...acc]
107+
},
108+
[],
109+
args,
110+
),
111+
),
112+
);
113+
} else if (List.length(args) > 0) {
114+
fprintf(ppf, "@[%s(%a)@]", cstr_name, pretty_vals(","), args);
97115
} else {
98-
fprintf(ppf, "@[%s@]", cstr.cstr_name);
116+
fprintf(ppf, "@[%s@]", cstr_name);
99117
}
100118
| TPatAlias(v, x, _) =>
101119
fprintf(ppf, "@[(%a@ as %a)@]", pretty_val, v, Ident.print, x)

0 commit comments

Comments
 (0)