Skip to content

Commit a1caf87

Browse files
authored
fix(compiler): Prevent impossible string error from pattern matching (#2218)
1 parent 0a49b0a commit a1caf87

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

compiler/src/typed/parmatch.re

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,8 @@ let untype_constant =
19391939
)
19401940
| Const_bytes(b) =>
19411941
Parsetree.PConstBytes(Location.mknoloc(Bytes.to_string(b)))
1942-
| Const_string(s) => Parsetree.PConstString(Location.mknoloc(s))
1942+
| Const_string(s) =>
1943+
Parsetree.PConstString(Location.mknoloc(Printf.sprintf("\"%s\"", s)))
19431944
| Const_char(c) => Parsetree.PConstChar(Location.mknoloc(c))
19441945
| Const_bool(b) => Parsetree.PConstBool(b)
19451946
| Const_void => Parsetree.PConstVoid;

compiler/test/suites/pattern_matching.re

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,4 +479,23 @@ describe("pattern matching", ({test, testSkip}) => {
479479
|},
480480
"Rec is a record constructor but a tuple constructor pattern was given.",
481481
);
482+
//
483+
assertWarning(
484+
"regression_2261_str_nested_list",
485+
{|
486+
match ([]) {
487+
["str"] => void,
488+
}
489+
|},
490+
Warnings.PartialMatch({|(["str", _, _]|["", _]|[])|}),
491+
);
492+
assertWarning(
493+
"regression_2261_str_nested_arr",
494+
{|
495+
match ([> ]) {
496+
[> "str"] => void,
497+
}
498+
|},
499+
Warnings.PartialMatch({|([> ""]|[> ])|}),
500+
);
482501
});

0 commit comments

Comments
 (0)