Bind star patterns in match statements (#3169)

This commit is contained in:
Charlie Marsh 2023-02-23 07:39:03 -05:00 committed by GitHub
parent ad7ba77fff
commit 0f04aa2a5f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View file

@ -20,7 +20,27 @@ def f(provided: int) -> int:
match provided:
case True:
return captured # F821
case [captured, *_]:
return captured
def f(provided: int) -> int:
match provided:
case captured:
return captured
def f(provided: int) -> int:
match provided:
case [captured, *_]:
return captured
def f(provided: int) -> int:
match provided:
case [*captured]:
return captured
def f(provided: int) -> int:
match provided:
case {**captured}:
return captured

View file

@ -3863,6 +3863,10 @@ where
fn visit_pattern(&mut self, pattern: &'b Pattern) {
if let PatternKind::MatchAs {
name: Some(name), ..
}
| PatternKind::MatchStar { name: Some(name) }
| PatternKind::MatchMapping {
rest: Some(name), ..
} = &pattern.node
{
self.add_binding(