mirror of
https://github.com/roc-lang/roc.git
synced 2025-11-14 10:15:41 +00:00
Add more test cases
This commit is contained in:
parent
be853b65c5
commit
041b91e031
2 changed files with 98 additions and 4 deletions
|
|
@ -5444,12 +5444,16 @@ fn is_inhabited(subs: &Subs, var: Variable) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FlatType::TagUnion(tags, ext) | FlatType::RecursiveTagUnion(_, tags, ext) => {
|
FlatType::TagUnion(tags, ext) | FlatType::RecursiveTagUnion(_, tags, ext) => {
|
||||||
let mut has_no_tags = true;
|
let mut is_uninhabited = true;
|
||||||
|
// If any tag is inhabited, the union is inhabited!
|
||||||
for (_tag, vars) in tags.unsorted_iterator(subs, *ext) {
|
for (_tag, vars) in tags.unsorted_iterator(subs, *ext) {
|
||||||
has_no_tags = false;
|
// Sadly we must recurse here...
|
||||||
stack.extend(vars);
|
let this_tag_is_inhabited = vars.iter().all(|v| is_inhabited(subs, *v));
|
||||||
|
if this_tag_is_inhabited {
|
||||||
|
is_uninhabited = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if has_no_tags {
|
if is_uninhabited {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10545,10 +10545,60 @@ All branches in an `if` must have the same type!
|
||||||
Ok {} -> ""
|
Ok {} -> ""
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
|
// no problem!
|
||||||
@r###"
|
@r###"
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test_report!(
|
||||||
|
uninhabited_type_is_trivially_exhaustive_nested,
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
x : Result (Result [A, B] []) []
|
||||||
|
|
||||||
|
when x is
|
||||||
|
Ok (Ok A) -> ""
|
||||||
|
Ok (Ok B) -> ""
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
// no problem!
|
||||||
|
@r###"
|
||||||
|
"###
|
||||||
|
);
|
||||||
|
|
||||||
|
test_report!(
|
||||||
|
#[ignore = "TODO https://github.com/roc-lang/roc/issues/4068"]
|
||||||
|
branch_patterns_missing_nested_case,
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
x : Result (Result [A, B] {}) {}
|
||||||
|
|
||||||
|
when x is
|
||||||
|
Ok (Ok A) -> ""
|
||||||
|
Err _ -> ""
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
@r###"
|
||||||
|
TODO
|
||||||
|
"###
|
||||||
|
);
|
||||||
|
|
||||||
|
test_report!(
|
||||||
|
#[ignore = "TODO https://github.com/roc-lang/roc/issues/4068"]
|
||||||
|
branch_patterns_missing_nested_case_with_trivially_exhausted_variant,
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
x : Result (Result [A, B] []) []
|
||||||
|
|
||||||
|
when x is
|
||||||
|
Ok (Ok A) -> ""
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
@r###"
|
||||||
|
TODO
|
||||||
|
"###
|
||||||
|
);
|
||||||
|
|
||||||
test_report!(
|
test_report!(
|
||||||
uninhabited_err_branch_is_redundant_when_err_is_matched,
|
uninhabited_err_branch_is_redundant_when_err_is_matched,
|
||||||
indoc!(
|
indoc!(
|
||||||
|
|
@ -10574,4 +10624,44 @@ All branches in an `if` must have the same type!
|
||||||
one should be removed.
|
one should be removed.
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test_report!(
|
||||||
|
uninhabited_err_branch_is_redundant_when_err_is_matched_nested,
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
x : Result (Result {} []) []
|
||||||
|
|
||||||
|
when x is
|
||||||
|
Ok (Ok {}) -> ""
|
||||||
|
Ok (Err _) -> ""
|
||||||
|
Err _ -> ""
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
@r###"
|
||||||
|
── REDUNDANT PATTERN ───────────────────────────────────── /code/proj/Main.roc ─
|
||||||
|
|
||||||
|
The 2nd pattern is redundant:
|
||||||
|
|
||||||
|
6│ when x is
|
||||||
|
7│ Ok (Ok {}) -> ""
|
||||||
|
8│> Ok (Err _) -> ""
|
||||||
|
9│ Err _ -> ""
|
||||||
|
|
||||||
|
Any value of this shape will be handled by a previous pattern, so this
|
||||||
|
one should be removed.
|
||||||
|
|
||||||
|
── REDUNDANT PATTERN ───────────────────────────────────── /code/proj/Main.roc ─
|
||||||
|
|
||||||
|
The 2nd pattern is redundant:
|
||||||
|
|
||||||
|
6│ when x is
|
||||||
|
7│ Ok (Ok {}) -> ""
|
||||||
|
8│ Ok (Err _) -> ""
|
||||||
|
9│ Err _ -> ""
|
||||||
|
^^^^^
|
||||||
|
|
||||||
|
Any value of this shape will be handled by a previous pattern, so this
|
||||||
|
one should be removed.
|
||||||
|
"###
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue