From 0ac2984a154f1a3f47dd054e2522b8aaee9b2cd9 Mon Sep 17 00:00:00 2001 From: Karl Meakin Date: Tue, 17 Jan 2023 05:40:33 +0000 Subject: [PATCH] Don't report check reachability for patterns with errors --- fathom/src/surface/elaboration/patterns.rs | 8 ++++++++ fathom/src/surface/elaboration/patterns/coverage.rs | 8 +++++++- tests/fail/elaboration/boolean-literal/not-supported.snap | 6 ------ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/fathom/src/surface/elaboration/patterns.rs b/fathom/src/surface/elaboration/patterns.rs index d441cab39..0e0747785 100644 --- a/fathom/src/surface/elaboration/patterns.rs +++ b/fathom/src/surface/elaboration/patterns.rs @@ -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)] @@ -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> { + self.pairs.iter().map(|(pattern, _)| pattern) + } } impl<'arena> CheckedPattern<'arena> { diff --git a/fathom/src/surface/elaboration/patterns/coverage.rs b/fathom/src/surface/elaboration/patterns/coverage.rs index adb50c89d..93fd43fd3 100644 --- a/fathom/src/surface/elaboration/patterns/coverage.rs +++ b/fathom/src/surface/elaboration/patterns/coverage.rs @@ -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()); } } diff --git a/tests/fail/elaboration/boolean-literal/not-supported.snap b/tests/fail/elaboration/boolean-literal/not-supported.snap index 666177fa8..0b362cde7 100644 --- a/tests/fail/elaboration/boolean-literal/not-supported.snap +++ b/tests/fail/elaboration/boolean-literal/not-supported.snap @@ -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, - │ ^^^^ - '''