Skip to content

Commit 8975fae

Browse files
committed
[ty] use Type::Divergent to avoid panic in infinitely-nested-tuple implicit attribute
1 parent 4c64ba4 commit 8975fae

File tree

7 files changed

+168
-78
lines changed

7 files changed

+168
-78
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/salsa-rs/salsa.git", rev = "3713cd7eb30821c0c086591832dd6f59f2af7fe7", 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
@@ -2419,6 +2419,16 @@ reveal_type(Answer.NO.value) # revealed: Any
24192419
reveal_type(Answer.__members__) # revealed: MappingProxyType[str, Unknown]
24202420
```
24212421

2422+
## Divergent inferred implicit instance attribute types
2423+
2424+
```py
2425+
class C:
2426+
def f(self, other: "C"):
2427+
self.x = (other.x,)
2428+
2429+
reveal_type((C().x,)) # revealed: tuple[Unknown | Divergent]
2430+
```
2431+
24222432
## References
24232433

24242434
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
@@ -762,6 +762,10 @@ impl<'db> Type<'db> {
762762
Self::Dynamic(DynamicType::Unknown)
763763
}
764764

765+
pub(crate) fn divergent(scope: ScopeId<'db>) -> Self {
766+
Self::Dynamic(DynamicType::Divergent(DivergentType { scope }))
767+
}
768+
765769
pub(crate) fn object(db: &'db dyn Db) -> Self {
766770
KnownClass::Object.to_instance(db)
767771
}
@@ -6516,7 +6520,6 @@ impl<'db> Type<'db> {
65166520
}
65176521
}
65186522

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

0 commit comments

Comments
 (0)