[ty] Narrow type context during literal promotion in generic class constructors (#21574)

## Summary

Resolves https://github.com/astral-sh/ty/issues/1603.
This commit is contained in:
Ibraheem Ahmed 2025-11-21 17:05:32 -05:00 committed by GitHub
parent 09d457aa52
commit 040aa7463b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View File

@ -335,6 +335,9 @@ reveal_type(x19) # revealed: list[Literal[1]]
x20: list[Literal[1]] | None = [1] x20: list[Literal[1]] | None = [1]
reveal_type(x20) # revealed: list[Literal[1]] reveal_type(x20) # revealed: list[Literal[1]]
x21: X[Literal[1]] | None = x(1) x21: X[Literal[1]] | None = X(1)
reveal_type(x21) # revealed: X[Literal[1]] reveal_type(x21) # revealed: X[Literal[1]]
x22: X[Literal[1]] | None = x(1)
reveal_type(x22) # revealed: X[Literal[1]]
``` ```

View File

@ -3504,9 +3504,10 @@ impl<'db> Type<'db> {
return; return;
}; };
let tcx_specialization = tcx let tcx_specialization = tcx.annotation.and_then(|tcx| {
.annotation tcx.filter_union(db, |ty| ty.specialization_of(db, class_literal).is_some())
.and_then(|tcx| tcx.specialization_of(db, class_literal)); .specialization_of(db, class_literal)
});
for (typevar, ty) in specialization for (typevar, ty) in specialization
.generic_context(db) .generic_context(db)