Skip to content

Commit

Permalink
fix(compiler): Prevent impossible string error from pattern matching (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
spotandjake authored Dec 29, 2024
1 parent 0a49b0a commit a1caf87
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/typed/parmatch.re
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,8 @@ let untype_constant =
)
| Const_bytes(b) =>
Parsetree.PConstBytes(Location.mknoloc(Bytes.to_string(b)))
| Const_string(s) => Parsetree.PConstString(Location.mknoloc(s))
| Const_string(s) =>
Parsetree.PConstString(Location.mknoloc(Printf.sprintf("\"%s\"", s)))
| Const_char(c) => Parsetree.PConstChar(Location.mknoloc(c))
| Const_bool(b) => Parsetree.PConstBool(b)
| Const_void => Parsetree.PConstVoid;
Expand Down
19 changes: 19 additions & 0 deletions compiler/test/suites/pattern_matching.re
Original file line number Diff line number Diff line change
Expand Up @@ -479,4 +479,23 @@ describe("pattern matching", ({test, testSkip}) => {
|},
"Rec is a record constructor but a tuple constructor pattern was given.",
);
//
assertWarning(
"regression_2261_str_nested_list",
{|
match ([]) {
["str"] => void,
}
|},
Warnings.PartialMatch({|(["str", _, _]|["", _]|[])|}),
);
assertWarning(
"regression_2261_str_nested_arr",
{|
match ([> ]) {
[> "str"] => void,
}
|},
Warnings.PartialMatch({|([> ""]|[> ])|}),
);
});

0 comments on commit a1caf87

Please sign in to comment.