[red-knot] Move standalone expr inference to for non-name target (#14788)

## Summary

Ref: https://github.com/astral-sh/ruff/pull/14754#discussion_r1871040646

## Test Plan

Remove the TODO comment and update the mdtest.
This commit is contained in:
Dhruv Manilawala 2024-12-05 18:06:20 +05:30 committed by GitHub
parent 43bf1a8907
commit e9941cd714
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 1 additions and 7 deletions

View file

@ -26,13 +26,10 @@ def True(for):
# error: [invalid-syntax] # error: [invalid-syntax]
pass pass
# TODO: Why is there two diagnostics for the same error?
# error: [invalid-syntax] # error: [invalid-syntax]
# error: [invalid-syntax] # error: [invalid-syntax]
# error: [invalid-syntax] # error: [invalid-syntax]
# error: [unresolved-reference] "Name `pass` used when not defined" # error: [unresolved-reference] "Name `pass` used when not defined"
# error: [unresolved-reference] "Name `pass` used when not defined"
for while in pass: for while in pass:
pass pass
@ -58,12 +55,10 @@ match while:
### Attribute expression ### Attribute expression
```py ```py
# TODO: Why is there two diagnostics for the same error?
# TODO: Check when support for attribute expressions is added # TODO: Check when support for attribute expressions is added
# error: [invalid-syntax] # error: [invalid-syntax]
# error: [unresolved-reference] "Name `foo` used when not defined" # error: [unresolved-reference] "Name `foo` used when not defined"
# error: [unresolved-reference] "Name `foo` used when not defined"
for x in foo.pass: for x in foo.pass:
pass pass
``` ```

View file

@ -1900,12 +1900,11 @@ impl<'db> TypeInferenceBuilder<'db> {
is_async: _, is_async: _,
} = for_statement; } = for_statement;
self.infer_standalone_expression(iter);
// TODO more complex assignment targets // TODO more complex assignment targets
if let ast::Expr::Name(name) = &**target { if let ast::Expr::Name(name) = &**target {
self.infer_definition(name); self.infer_definition(name);
} else { } else {
self.infer_standalone_expression(iter);
self.infer_expression(target); self.infer_expression(target);
} }
self.infer_body(body); self.infer_body(body);