Skip to content

Commit 0ddae6b

Browse files
update on comment
1 parent cff3704 commit 0ddae6b

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
@@ -912,7 +912,12 @@ fn function_last_expressions<'a>(
912912
let mut syntactically_exhaustive = false;
913913
for case in x.cases.iter() {
914914
f(sys_info, &case.body, res)?;
915-
if pattern_is_syntactically_exhaustive_for_subject(&x.subject, &case.pattern) {
915+
if case.guard.is_none()
916+
&& pattern_is_syntactically_exhaustive_for_subject(
917+
&x.subject,
918+
&case.pattern,
919+
)
920+
{
916921
syntactically_exhaustive = true;
917922
break;
918923
}

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)