Skip to content

Commit

Permalink
Don't report check reachability for patterns with errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Kmeakin committed Jan 17, 2023
1 parent ee05bd1 commit 0ac2984
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 8 additions & 0 deletions fathom/src/surface/elaboration/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ impl<'arena> CheckedPattern<'arena> {
CheckedPattern::RecordLit(_, _, _) => false,
}
}

pub fn is_error(&self) -> bool {
matches!(self, CheckedPattern::ReportedError(_))
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -625,6 +629,10 @@ impl<'arena> PatRow<'arena> {
pub fn append(&mut self, mut other: Self) {
self.pairs.append(&mut other.pairs);
}

pub fn patterns(&self) -> impl ExactSizeIterator<Item = &CheckedPattern<'arena>> {
self.pairs.iter().map(|(pattern, _)| pattern)
}
}

impl<'arena> CheckedPattern<'arena> {
Expand Down
8 changes: 7 additions & 1 deletion fathom/src/surface/elaboration/patterns/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ pub fn check_coverage<'arena>(
let mut rows = Vec::with_capacity(matrix.num_rows());
for (row, _) in matrix.iter() {
let matrix = PatMatrix::new(rows.clone());
rows.push(row.clone());

// Don't check reachability for patterns with errors
if row.patterns().any(|pattern| pattern.is_error()) {
continue;
}

if !is_useful(ctx, &matrix, row) {
let range = row.first().unwrap().0.range();
ctx.push_message(Message::UnreachablePattern {
range: ctx.file_range(range),
});
}
rows.push(row.clone());
}
}

Expand Down
6 changes: 0 additions & 6 deletions tests/fail/elaboration/boolean-literal/not-supported.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,4 @@ error: boolean literal not supported for expected type
7 │ true => 1,
│ ^^^^
warning: unreachable pattern
┌─ tests/fail/elaboration/boolean-literal/not-supported.fathom:7:5
7 │ true => 1,
│ ^^^^
'''

0 comments on commit 0ac2984

Please sign in to comment.