Skip to content

Commit 35a68be

Browse files
yangdanny97meta-codesync[bot]
authored andcommitted
don't crash on unbound name in match star pattern
Reviewed By: migeed-z Differential Revision: D88674472 fbshipit-source-id: d2d8d152169e1de1a810ec39d966db6e81f11f2e
1 parent 99722e0 commit 35a68be

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

pyrefly/lib/binding/pattern.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,12 @@ impl<'a> BindingsBuilder<'a> {
333333
self.finish_match_or_fork();
334334
narrow_ops.unwrap_or_default()
335335
}
336-
Pattern::MatchStar(_) => NarrowOps::new(),
336+
Pattern::MatchStar(p) => {
337+
if let Some(name) = &p.name {
338+
self.bind_definition(name, Binding::Forward(subject_idx), FlowStyle::Other);
339+
}
340+
NarrowOps::new()
341+
}
337342
}
338343
}
339344

pyrefly/lib/test/flow_branching.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ match x:
721721
);
722722

723723
testcase!(
724-
test_crashing_match,
724+
test_crashing_match_sequence,
725725
r#"
726726
match []:
727727
case [[1]]:
@@ -731,6 +731,19 @@ match []:
731731
"#,
732732
);
733733

734+
testcase!(
735+
test_crashing_match_star,
736+
r#"
737+
match []:
738+
case *x: # E: Parse error: Star pattern cannot be used here
739+
pass
740+
case *x | 1: # E: Parse error: Star pattern cannot be used here # E: alternative patterns bind different names
741+
pass
742+
case 1 | *x: # E: Parse error: Star pattern cannot be used here # E: alternative patterns bind different names
743+
pass
744+
"#,
745+
);
746+
734747
testcase!(
735748
test_match_narrow_generic,
736749
r#"

0 commit comments

Comments
 (0)