Skip to content

Commit e9941cd

Browse files
authored
[red-knot] Move standalone expr inference to for non-name target (#14788)
## Summary Ref: #14754 (comment) ## Test Plan Remove the TODO comment and update the mdtest.
1 parent 43bf1a8 commit e9941cd

File tree

2 files changed

+1
-7
lines changed

2 files changed

+1
-7
lines changed

crates/red_knot_python_semantic/resources/mdtest/invalid_syntax.md

-5
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@ def True(for):
2626
# error: [invalid-syntax]
2727
pass
2828

29-
# TODO: Why is there two diagnostics for the same error?
30-
3129
# error: [invalid-syntax]
3230
# error: [invalid-syntax]
3331
# error: [invalid-syntax]
3432
# error: [unresolved-reference] "Name `pass` used when not defined"
35-
# error: [unresolved-reference] "Name `pass` used when not defined"
3633
for while in pass:
3734
pass
3835

@@ -58,12 +55,10 @@ match while:
5855
### Attribute expression
5956

6057
```py
61-
# TODO: Why is there two diagnostics for the same error?
6258
# TODO: Check when support for attribute expressions is added
6359

6460
# error: [invalid-syntax]
6561
# error: [unresolved-reference] "Name `foo` used when not defined"
66-
# error: [unresolved-reference] "Name `foo` used when not defined"
6762
for x in foo.pass:
6863
pass
6964
```

crates/red_knot_python_semantic/src/types/infer.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1900,12 +1900,11 @@ impl<'db> TypeInferenceBuilder<'db> {
19001900
is_async: _,
19011901
} = for_statement;
19021902

1903-
self.infer_standalone_expression(iter);
1904-
19051903
// TODO more complex assignment targets
19061904
if let ast::Expr::Name(name) = &**target {
19071905
self.infer_definition(name);
19081906
} else {
1907+
self.infer_standalone_expression(iter);
19091908
self.infer_expression(target);
19101909
}
19111910
self.infer_body(body);

0 commit comments

Comments
 (0)