Skip to content

Commit 816a7e7

Browse files
cknittclaude
andauthored
Write missing-case examples beyond char literals as ints
A missing-case example in a char column took the kind of the first pattern, so a value that no char literal can denote was printed as an invalid one: a switch covering every char literal suggested `'\u{110000}'`. Such values are now printed as ints. Example (rescript): let f = c => switch c { | '\u{0}' .. '\u{10FFFF}' => 1 } Before (text): You forgot to handle a possible case here, for example: | '\u{110000}' After (text): You forgot to handle a possible case here, for example: | 1114112 Source: tests/build_tests/super_errors/fixtures/warning_8_char_range_beyond.res, compiled with the parent commit and with this one. Review: Codex found this for mixed ranges on #8894, where an example below 0 was printed as a char; the cause is here. Area: typechecker tests Output: unchanged Errors: ERROR_VARIANTS.md warnings section lists warning_8_char_range_beyond.res Tests: +tests/build_tests/super_errors/fixtures/warning_8_char_range_beyond.res Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JALXUyHhkDqzcB3WuW9Svo Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent cc6be0b commit 816a7e7

4 files changed

Lines changed: 28 additions & 6 deletions

File tree

‎compiler/ml/parmatch.ml‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,17 @@ let int_range p =
125125
Some (lo, hi)
126126
| _ -> None
127127

128-
(* A constant or interval for [lo .. hi], of the same kind as [p]. *)
128+
(* A constant or interval for [lo .. hi], of the same kind as [p]: chars when
129+
[p] starts with a char and the bounds can be written as char literals. *)
129130
let make_int_range p lo hi =
130-
let const i =
131+
let chars =
132+
Uchar.is_valid lo && Uchar.is_valid hi
133+
&&
131134
match p.pat_desc with
132-
| Tpat_constant (Const_char _) | Tpat_interval (Const_char _, _) ->
133-
Const_char i
134-
| _ -> Const_int i
135+
| Tpat_constant (Const_char _) | Tpat_interval (Const_char _, _) -> true
136+
| _ -> false
135137
in
138+
let const i = if chars then Const_char i else Const_int i in
136139
let desc =
137140
if lo = hi then Tpat_constant (const lo)
138141
else Tpat_interval (const lo, const hi)

‎tests/ERROR_VARIANTS.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,8 @@ so coverage gaps stay greppable. Warning 11 (`Unused_match`) is covered by
563563
`warning_11_equivalent_char_int_patterns.res` and
564564
`warning_11_char_range_covered.res`, warning 8 (`Partial_match`) on mixed
565565
char and int patterns by `warning_8_char_int_patterns.res` and with a range
566-
in its example by `warning_8_char_range_example.res`, and warning 111
566+
in its example by `warning_8_char_range_example.res` and with an int example
567+
beyond all char literals by `warning_8_char_range_beyond.res`, and warning 111
567568
(`Bs_private_record_mutation`, a write to a private record field) by
568569
`private_label.res`.
569570

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
Warning number 8
3+
/.../fixtures/warning_8_char_range_beyond.res:3:3-5:3
4+
5+
1 │ // All char literals are covered, so the example is an int beyond them.
6+
2 │ let f = c =>
7+
3 │ switch c {
8+
4 │  | '\u{0}' .. '\u{10FFFF}' => 1
9+
5 │  }
10+
6 │
11+
12+
You forgot to handle a possible case here, for example:
13+
| 1114112
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// All char literals are covered, so the example is an int beyond them.
2+
let f = c =>
3+
switch c {
4+
| '\u{0}' .. '\u{10FFFF}' => 1
5+
}

0 commit comments

Comments
 (0)