statically known to be True branches

This commit is contained in:
David Peter
2024-11-28 14:33:12 +01:00
parent 5be842b1c3
commit eb4ae2b910
8 changed files with 234 additions and 38 deletions

View File

@@ -29,7 +29,8 @@ if (x := 1) or bool_instance():
reveal_type(x) # revealed: Literal[1]
if (x := 1) and bool_instance():
reveal_type(x) # revealed: Literal[1]
# TODO
reveal_type(x) # revealed: Never
```
## Statically known truthiness
@@ -38,12 +39,13 @@ if (x := 1) and bool_instance():
if True or (x := 1):
# TODO: infer that the second arm is never executed, and raise `unresolved-reference`.
# error: [possibly-unresolved-reference]
reveal_type(x) # revealed: Literal[1]
reveal_type(x) # revealed: Never
if True and (x := 1):
# TODO: infer that the second arm is always executed, do not raise a diagnostic
# TODO
# error: [possibly-unresolved-reference]
reveal_type(x) # revealed: Literal[1]
reveal_type(x) # revealed: Never
```
## Later expressions can always use variables from earlier expressions