Narrowing for class patterns in match statements (#15223)

We now support class patterns in a match statement, adding a narrowing
constraint that within the body of that match arm, we can assume that
the subject is an instance of that class.

---------

Co-authored-by: Carl Meyer <carl@astral.sh>
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
Douglas Creager 2025-01-07 15:58:12 -05:00 committed by GitHub
parent f2a86fcfda
commit b2a0d68d70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 151 additions and 43 deletions

View file

@ -329,9 +329,9 @@ impl<'db> VisibilityConstraints<'db> {
Truthiness::Ambiguous
}
}
PatternConstraintKind::Singleton(..) | PatternConstraintKind::Unsupported => {
Truthiness::Ambiguous
}
PatternConstraintKind::Singleton(..)
| PatternConstraintKind::Class(..)
| PatternConstraintKind::Unsupported => Truthiness::Ambiguous,
},
}
}