Skip to content

Commit 9864e93

Browse files
update on comment
1 parent d7a3f66 commit 9864e93

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

pyrefly/lib/binding/function.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,12 @@ fn function_last_expressions<'a>(
975975
let mut syntactically_exhaustive = false;
976976
for case in x.cases.iter() {
977977
f(sys_info, &case.body, res)?;
978-
if pattern_is_syntactically_exhaustive_for_subject(&x.subject, &case.pattern) {
978+
if case.guard.is_none()
979+
&& pattern_is_syntactically_exhaustive_for_subject(
980+
&x.subject,
981+
&case.pattern,
982+
)
983+
{
979984
syntactically_exhaustive = true;
980985
break;
981986
}

pyrefly/lib/binding/pattern.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,8 @@ impl<'a> BindingsBuilder<'a> {
580580
..
581581
} = case;
582582
self.start_branch();
583-
let case_is_irrefutable =
584-
pattern_is_syntactically_exhaustive_for_subject(&subject_expr, &pattern);
583+
let case_is_irrefutable = guard.is_none()
584+
&& pattern_is_syntactically_exhaustive_for_subject(&subject_expr, &pattern);
585585
if case_is_irrefutable {
586586
exhaustive = true;
587587
}

pyrefly/lib/test/pattern_match.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,41 @@ def test(x: int | None, y: int | None) -> int:
848848
"#,
849849
);
850850

851+
testcase!(
852+
test_match_multi_subject_guarded_tuple_catch_all_is_not_exhaustive,
853+
r#"
854+
from typing import assert_type
855+
856+
def test(x: int | None, y: int | None, cond: bool) -> None:
857+
match x, y:
858+
case None, None:
859+
raise ValueError
860+
case int(m), None:
861+
u = m * 3
862+
v = m
863+
case None, int(n):
864+
u = n
865+
v = n // 3
866+
case _, _ if cond:
867+
raise ValueError
868+
869+
assert_type(u, int) # E: `u` may be uninitialized
870+
assert_type(v, int) # E: `v` may be uninitialized
871+
"#,
872+
);
873+
874+
testcase!(
875+
test_match_multi_subject_guarded_tuple_catch_all_counts_for_return_analysis,
876+
r#"
877+
def test(x: int | None, y: int | None, cond: bool) -> int: # E: Function declared to return `int`, but one or more paths are missing an explicit `return`
878+
match x, y:
879+
case None, None:
880+
return 0
881+
case _, _ if cond:
882+
return 1
883+
"#,
884+
);
885+
851886
testcase!(
852887
test_exhaustive_enum_or_pattern_no_missing_return,
853888
r#"

0 commit comments

Comments
 (0)