mention false positive errors caused in possibly-unreachable branches

This commit is contained in:
Shunsuke Shibayama 2025-12-06 23:40:23 +09:00
parent 938ae0eae6
commit 1b9434bd09
2 changed files with 24 additions and 2 deletions

View File

@ -644,6 +644,28 @@ reveal_type(C(True).d) # revealed: Unknown | Literal[5]
reveal_type(C(True).e) # revealed: Unknown
```
#### Attributes defined in possibly-unreachable branches
```py
from typing import Callable
class C:
def __init__(self, cond: Callable[[], bool]) -> None:
i = 0
while cond():
i += 1
# TODO: this should be `int`
reveal_type(i) # revealed: Literal[0, 1]
if i < 100:
return
self.x = 1
# TODO: this should be a possibly-unresolved-attribute error, not unresolved-attribute
# error: [unresolved-attribute]
reveal_type(C(lambda: False).x) # revealed: Unknown
```
#### Attributes considered always bound
```py

View File

@ -729,7 +729,7 @@ impl<'map, 'db> Iterator for BindingWithConstraintsIterator<'map, 'db> {
impl std::iter::FusedIterator for BindingWithConstraintsIterator<'_, '_> {}
/// An iterator of reachable bindings, i.e. bindings that were reachable before return/break etc. was invoked.
/// An iterator of referable bindings, i.e. bindings that were reachable before return/break etc. was invoked.
pub(crate) struct ReferableBindingWithConstraintsIterator<'map, 'db> {
inner: BindingWithConstraintsIterator<'map, 'db>,
use_def_map: &'map UseDefMap<'db>,
@ -845,7 +845,7 @@ impl<'db> Iterator for DeclarationsIterator<'_, 'db> {
impl std::iter::FusedIterator for DeclarationsIterator<'_, '_> {}
/// An iterator of reachable declarations, i.e. declarations that were reachable before return/break etc. was invoked.
/// An iterator of referable declarations, i.e. declarations that were reachable before return/break etc. was invoked.
pub(crate) struct ReferableDeclarationsIterator<'map, 'db> {
inner: DeclarationsIterator<'map, 'db>,
use_def_map: &'map UseDefMap<'db>,