Check exhaustiveness behavior on pattern guards.

This commit is contained in:
KtorZ 2023-08-02 10:40:59 +02:00
parent 4f7f39292d
commit 675b737898
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
1 changed files with 24 additions and 0 deletions

View File

@ -611,6 +611,30 @@ fn exhaustiveness_nested_list_and_tuples() {
assert!(matches!(check(parse(source_code)), Ok(_))) assert!(matches!(check(parse(source_code)), Ok(_)))
} }
#[test]
fn exhaustiveness_guard() {
let source_code = r#"
fn foo() {
when [(True, 42)] is {
[(True, x), ..] if x == 42 -> Void
[(False, x), ..] -> Void
[] -> Void
}
}
"#;
assert!(matches!(
check(parse(source_code)),
Err((
_,
Error::NotExhaustivePatternMatch {
unmatched,
..
}
)) if unmatched[0] == "[(True, _), ..]"
));
}
#[test] #[test]
fn expect_sugar_correct_type() { fn expect_sugar_correct_type() {
let source_code = r#" let source_code = r#"