Skip to content

Commit 0ac2984

Browse files
committed
Don't report check reachability for patterns with errors
1 parent ee05bd1 commit 0ac2984

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

fathom/src/surface/elaboration/patterns.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ impl<'arena> CheckedPattern<'arena> {
6363
CheckedPattern::RecordLit(_, _, _) => false,
6464
}
6565
}
66+
67+
pub fn is_error(&self) -> bool {
68+
matches!(self, CheckedPattern::ReportedError(_))
69+
}
6670
}
6771

6872
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
@@ -625,6 +629,10 @@ impl<'arena> PatRow<'arena> {
625629
pub fn append(&mut self, mut other: Self) {
626630
self.pairs.append(&mut other.pairs);
627631
}
632+
633+
pub fn patterns(&self) -> impl ExactSizeIterator<Item = &CheckedPattern<'arena>> {
634+
self.pairs.iter().map(|(pattern, _)| pattern)
635+
}
628636
}
629637

630638
impl<'arena> CheckedPattern<'arena> {

fathom/src/surface/elaboration/patterns/coverage.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,19 @@ pub fn check_coverage<'arena>(
3636
let mut rows = Vec::with_capacity(matrix.num_rows());
3737
for (row, _) in matrix.iter() {
3838
let matrix = PatMatrix::new(rows.clone());
39+
rows.push(row.clone());
40+
41+
// Don't check reachability for patterns with errors
42+
if row.patterns().any(|pattern| pattern.is_error()) {
43+
continue;
44+
}
45+
3946
if !is_useful(ctx, &matrix, row) {
4047
let range = row.first().unwrap().0.range();
4148
ctx.push_message(Message::UnreachablePattern {
4249
range: ctx.file_range(range),
4350
});
4451
}
45-
rows.push(row.clone());
4652
}
4753
}
4854

tests/fail/elaboration/boolean-literal/not-supported.snap

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,4 @@ error: boolean literal not supported for expected type
1212
7true => 1,
1313
^^^^
1414

15-
warning: unreachable pattern
16-
┌─ tests/fail/elaboration/boolean-literal/not-supported.fathom:7:5
17-
18-
7true => 1,
19-
^^^^
20-
2115
'''

0 commit comments

Comments
 (0)