[red-knot] Avoid unresolved-reference in unreachable code (#17169)
## Summary This PR changes the inferred type for symbols in unreachable sections of code to `Never` (instead of reporting them as unbound), in order to silence false positive diagnostics. See the lengthy comment in the code for further details. ## Test Plan - Updated Markdown tests. - Manually verified a couple of ecosystem diagnostic changes.
This commit is contained in:
@@ -654,9 +654,7 @@ def f(cond: bool) -> str:
|
||||
reveal_type(x) # revealed: Literal["before"]
|
||||
return "a"
|
||||
x = "after-return"
|
||||
# TODO: no unresolved-reference error
|
||||
# error: [unresolved-reference]
|
||||
reveal_type(x) # revealed: Unknown
|
||||
reveal_type(x) # revealed: Never
|
||||
else:
|
||||
x = "else"
|
||||
return reveal_type(x) # revealed: Literal["else"]
|
||||
|
||||
@@ -211,9 +211,6 @@ def f():
|
||||
|
||||
print("unreachable")
|
||||
|
||||
# TODO: we should not emit an error here; we currently do, since there is no control flow path from this
|
||||
# use of 'x' to any definition of 'x'.
|
||||
# error: [unresolved-reference]
|
||||
print(x)
|
||||
```
|
||||
|
||||
@@ -228,8 +225,6 @@ def outer():
|
||||
x = 1
|
||||
|
||||
def inner():
|
||||
# TODO: we should not emit an error here
|
||||
# error: [unresolved-reference]
|
||||
return x # Name `x` used when not defined
|
||||
while True:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user