mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
[ty] Fix assignability checks for invariant generics parameterized by gradual types (#18138)
This commit is contained in:
parent
28fb802467
commit
0adbb3d600
2 changed files with 61 additions and 2 deletions
|
@ -457,10 +457,13 @@ impl<'db> Specialization<'db> {
|
|||
// corresponding typevar:
|
||||
// - covariant: verify that self_type <: other_type
|
||||
// - contravariant: verify that other_type <: self_type
|
||||
// - invariant: verify that self_type == other_type
|
||||
// - invariant: verify that self_type <: other_type AND other_type <: self_type
|
||||
// - bivariant: skip, can't make assignability false
|
||||
let compatible = match typevar.variance(db) {
|
||||
TypeVarVariance::Invariant => self_type.is_gradual_equivalent_to(db, *other_type),
|
||||
TypeVarVariance::Invariant => {
|
||||
self_type.is_assignable_to(db, *other_type)
|
||||
&& other_type.is_assignable_to(db, *self_type)
|
||||
}
|
||||
TypeVarVariance::Covariant => self_type.is_assignable_to(db, *other_type),
|
||||
TypeVarVariance::Contravariant => other_type.is_assignable_to(db, *self_type),
|
||||
TypeVarVariance::Bivariant => true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue