Skip to content

Commit cd3267c

Browse files
fix(compiler): Correct impossible bug on nested char pattern (#2310)
Co-authored-by: Oscar Spencer <oscar@grain-lang.org>
1 parent 2f2dad4 commit cd3267c

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

compiler/src/typed/parmatch.re

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2099,7 +2099,8 @@ let untype_constant =
20992099
Parsetree.PConstBytes(Location.mknoloc(Bytes.to_string(b)))
21002100
| Const_string(s) =>
21012101
Parsetree.PConstString(Location.mknoloc(Printf.sprintf("\"%s\"", s)))
2102-
| Const_char(c) => Parsetree.PConstChar(Location.mknoloc(c))
2102+
| Const_char(c) =>
2103+
Parsetree.PConstChar(Location.mknoloc(Printf.sprintf("\'%s\'", c)))
21032104
| Const_bool(b) => Parsetree.PConstBool(b)
21042105
| Const_void => Parsetree.PConstVoid;
21052106

compiler/src/typed/printpat.re

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ let pretty_const = c =>
3434
| Const_number(Const_number_bigint({bigint_rep})) => bigint_rep
3535
| Const_bytes(b) => Printf.sprintf("%S", Bytes.to_string(b))
3636
| Const_string(s) => Printf.sprintf("%S", s)
37-
| Const_char(c) => Printf.sprintf("%S", c)
37+
| Const_char(c) => Printf.sprintf("\'%s\'", c)
3838
| Const_float64(f)
3939
| Const_float32(f) => Printf.sprintf("%f", f)
4040
| Const_int8(i) => Printf.sprintf("%lds", i)

compiler/test/suites/pattern_matching.re

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ describe("pattern matching", ({test, testSkip}) => {
236236
"constant_match_4",
237237
"match ((\"foo\", 5)) { (\"foo\", n) when n == 7 => false, (\"foo\", 9) when true => false, (\"foo\", n) when n == 5 => true, _ => false }",
238238
);
239+
assertWarning(
240+
"nested_constant_match_1",
241+
"match ([> 'a']) {
242+
[> 'l', 'e'] => void,
243+
}",
244+
Warnings.PartialMatch("([> 'l', _]|[> _, _]|[> ])"),
245+
);
239246
// Constant low level wasm type patterns
240247
assertSnapshot(
241248
"low_level_constant_match_1",

0 commit comments

Comments
 (0)