@@ -1567,16 +1567,20 @@ impl<'db> Type<'db> {
15671567 // However, there is one exception to this general rule: for any given typevar `T`,
15681568 // `T` will always be a subtype of any union containing `T`.
15691569 // A similar rule applies in reverse to intersection types.
1570- ( Type :: TypeVar ( _) , Type :: Union ( union) ) if union. elements ( db) . contains ( & self ) => {
1570+ ( Type :: TypeVar ( bound_typevar) , Type :: Union ( union) )
1571+ if !inferable. is_inferable ( bound_typevar) && union. elements ( db) . contains ( & self ) =>
1572+ {
15711573 ConstraintSet :: from ( true )
15721574 }
1573- ( Type :: Intersection ( intersection) , Type :: TypeVar ( _) )
1574- if intersection. positive ( db) . contains ( & target) =>
1575+ ( Type :: Intersection ( intersection) , Type :: TypeVar ( bound_typevar) )
1576+ if !inferable. is_inferable ( bound_typevar)
1577+ && intersection. positive ( db) . contains ( & target) =>
15751578 {
15761579 ConstraintSet :: from ( true )
15771580 }
1578- ( Type :: Intersection ( intersection) , Type :: TypeVar ( _) )
1579- if intersection. negative ( db) . contains ( & target) =>
1581+ ( Type :: Intersection ( intersection) , Type :: TypeVar ( bound_typevar) )
1582+ if !inferable. is_inferable ( bound_typevar)
1583+ && intersection. negative ( db) . contains ( & target) =>
15801584 {
15811585 ConstraintSet :: from ( false )
15821586 }
@@ -1700,7 +1704,8 @@ impl<'db> Type<'db> {
17001704 }
17011705
17021706 ( _, Type :: TypeVar ( typevar) )
1703- if relation. is_assignability ( )
1707+ if inferable. is_inferable ( typevar)
1708+ && relation. is_assignability ( )
17041709 && typevar. typevar ( db) . upper_bound ( db) . is_none_or ( |bound| {
17051710 !self
17061711 . has_relation_to_impl ( db, bound, inferable, relation, visitor)
@@ -1715,7 +1720,11 @@ impl<'db> Type<'db> {
17151720 }
17161721
17171722 // TODO: Infer specializations here
1718- ( Type :: TypeVar ( _) , _) | ( _, Type :: TypeVar ( _) ) => ConstraintSet :: from ( false ) ,
1723+ ( Type :: TypeVar ( bound_typevar) , _) | ( _, Type :: TypeVar ( bound_typevar) )
1724+ if inferable. is_inferable ( bound_typevar) =>
1725+ {
1726+ ConstraintSet :: from ( false )
1727+ }
17191728
17201729 ( Type :: TypedDict ( _) , _) | ( _, Type :: TypedDict ( _) ) => {
17211730 // TODO: Implement assignability and subtyping for TypedDict
@@ -2016,6 +2025,11 @@ impl<'db> Type<'db> {
20162025
20172026 // Other than the special cases enumerated above, `Instance` types and typevars are
20182027 // never subtypes of any other variants
2028+ ( Type :: TypeVar ( bound_typevar) , _) => {
2029+ // All inferable cases should have been handled above
2030+ debug_assert ! ( !inferable. is_inferable( bound_typevar) ) ;
2031+ ConstraintSet :: from ( false )
2032+ }
20192033 ( Type :: NominalInstance ( _) , _) => ConstraintSet :: from ( false ) ,
20202034 }
20212035 }
0 commit comments