Skip to content

Commit

Permalink
frontend: Fix pattern argument in check_useful
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Dec 14, 2024
1 parent 1d716ac commit d3581f8
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions dora-frontend/src/exhaustiveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,8 @@ fn discover_signature_for_pattern(
fn check_useful(matrix: Vec<Vec<Pattern>>, mut pattern: Vec<Pattern>) -> bool {
let n = pattern.len();

if n > 0 {
for row in &matrix {
assert_eq!(row.len(), n);
}
for row in &matrix {
assert_eq!(row.len(), n);
}

if matrix.is_empty() {
Expand Down Expand Up @@ -556,24 +554,26 @@ fn check_useful(matrix: Vec<Vec<Pattern>>, mut pattern: Vec<Pattern>) -> bool {
check_useful(new_matrix, pattern)
}

Pattern::EnumVariant(_enum_id, variant_id, params) => {
Pattern::EnumVariant(_enum_id, variant_id, mut params) => {
let arity = params.len();
let new_matrix = matrix
.iter()
.flat_map(|r| specialize_row_for_constructor(r, variant_id, arity))
.collect::<Vec<_>>();

pattern.append(&mut params);
check_useful(new_matrix, pattern)
}

Pattern::Tuple(params) => {
Pattern::Tuple(mut params) => {
let arity = params.len();

let new_matrix = matrix
.iter()
.flat_map(|r| specialize_row_for_constructor(r, 0, arity))
.collect::<Vec<_>>();

pattern.append(&mut params);
check_useful(new_matrix, pattern)
}
}
Expand Down Expand Up @@ -966,6 +966,26 @@ mod tests {
);
}

#[test]
fn usefulness_enum() {
err(
"
enum Foo { A(Int), C(Bool), D(Int, Bool) }
@NewExhaustiveness @CheckUsefulness
fn f(v: Foo) {
match v {
Foo::C(_) => {}
Foo::C(_) => {}
_ => {}
}
}
",
(8, 21),
ErrorMessage::MatchUnreachablePattern,
);
}

#[test]
fn exhaustive_bool() {
ok("
Expand Down

0 comments on commit d3581f8

Please sign in to comment.