mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +00:00
[red-knot] Fix assertion for invalid match pattern (#14306)
## Summary Fixes a failing debug assertion that triggers for the following code: ```py match some_int: case x:=2: pass ``` closes #14305 ## Test Plan Added problematic code example to corpus.
This commit is contained in:
parent
5c548dcc04
commit
3e36a7ab81
2 changed files with 15 additions and 9 deletions
|
@ -4084,16 +4084,19 @@ impl<'db> TypeInferenceBuilder<'db> {
|
|||
// https://typing.readthedocs.io/en/latest/spec/annotations.html#grammar-token-expression-grammar-type_expression
|
||||
|
||||
match expression {
|
||||
ast::Expr::Name(name) => {
|
||||
debug_assert_eq!(name.ctx, ast::ExprContext::Load);
|
||||
self.infer_name_expression(name).to_instance(self.db)
|
||||
}
|
||||
ast::Expr::Name(name) => match name.ctx {
|
||||
ast::ExprContext::Load => self.infer_name_expression(name).to_instance(self.db),
|
||||
ast::ExprContext::Invalid => Type::Unknown,
|
||||
ast::ExprContext::Store | ast::ExprContext::Del => Type::Todo,
|
||||
},
|
||||
|
||||
ast::Expr::Attribute(attribute_expression) => {
|
||||
debug_assert_eq!(attribute_expression.ctx, ast::ExprContext::Load);
|
||||
self.infer_attribute_expression(attribute_expression)
|
||||
.to_instance(self.db)
|
||||
}
|
||||
ast::Expr::Attribute(attribute_expression) => match attribute_expression.ctx {
|
||||
ast::ExprContext::Load => self
|
||||
.infer_attribute_expression(attribute_expression)
|
||||
.to_instance(self.db),
|
||||
ast::ExprContext::Invalid => Type::Unknown,
|
||||
ast::ExprContext::Store | ast::ExprContext::Del => Type::Todo,
|
||||
},
|
||||
|
||||
ast::Expr::NoneLiteral(_literal) => Type::none(self.db),
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
match some_int:
|
||||
case x:=2:
|
||||
pass
|
Loading…
Add table
Add a link
Reference in a new issue