Skip to content

Commit 5a78c17

Browse files
committed
[ty] use Type::Divergent to avoid panic in infinitely-nested-tuple implicit attribute
1 parent da15f9a commit 5a78c17

File tree

7 files changed

+170
-75
lines changed

7 files changed

+170
-75
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ regex-automata = { version = "0.4.9" }
143143
rustc-hash = { version = "2.0.0" }
144144
rustc-stable-hash = { version = "0.1.2" }
145145
# When updating salsa, make sure to also update the revision in `fuzz/Cargo.toml`
146-
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "a3ffa22cb26756473d56f867aedec3fd907c4dd9", default-features = false, features = [
146+
salsa = { git = "https://github.com/carljm/salsa.git", rev = "45cd920389c0e18da4dece07761a8afe532b4c91", default-features = false, features = [
147147
"compact_str",
148148
"macros",
149149
"salsa_unstable",

crates/ty_python_semantic/resources/mdtest/attributes.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,6 +2414,16 @@ reveal_type(Answer.NO.value) # revealed: Any
24142414
reveal_type(Answer.__members__) # revealed: MappingProxyType[str, Unknown]
24152415
```
24162416

2417+
## Divergent inferred implicit instance attribute types
2418+
2419+
```py
2420+
class C:
2421+
def f(self, other: "C"):
2422+
self.x = (other.x,)
2423+
2424+
reveal_type((C().x,)) # revealed: tuple[Unknown | Divergent]
2425+
```
2426+
24172427
## References
24182428

24192429
Some of the tests in the *Class and instance variables* section draw inspiration from

crates/ty_python_semantic/src/types.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,10 @@ impl<'db> Type<'db> {
720720
Self::Dynamic(DynamicType::Unknown)
721721
}
722722

723+
pub(crate) fn divergent(scope: ScopeId<'db>) -> Self {
724+
Self::Dynamic(DynamicType::Divergent(DivergentType { scope }))
725+
}
726+
723727
pub(crate) fn object(db: &'db dyn Db) -> Self {
724728
KnownClass::Object.to_instance(db)
725729
}
@@ -6571,7 +6575,6 @@ impl<'db> Type<'db> {
65716575
}
65726576
}
65736577

6574-
#[allow(unused)]
65756578
pub(super) fn has_divergent_type(self, db: &'db dyn Db, div: Type<'db>) -> bool {
65766579
any_over_type(db, self, &|ty| match ty {
65776580
Type::Dynamic(DynamicType::Divergent(_)) => ty == div,

0 commit comments

Comments
 (0)