fix recursive protocols

This commit is contained in:
Alex Waygood 2025-07-01 13:09:55 +01:00
parent 66932b5087
commit c548b0d085
2 changed files with 14 additions and 7 deletions

View file

@ -1773,7 +1773,8 @@ class RecursiveOptionalParent(Protocol):
static_assert(is_assignable_to(RecursiveOptionalParent, RecursiveOptionalParent))
static_assert(is_assignable_to(RecursiveNonFullyStatic, RecursiveOptionalParent))
# Due to invariance of mutable attribute members, neither is assignable to the other
static_assert(not is_assignable_to(RecursiveNonFullyStatic, RecursiveOptionalParent))
static_assert(not is_assignable_to(RecursiveOptionalParent, RecursiveNonFullyStatic))
class Other(Protocol):

View file

@ -152,13 +152,19 @@ impl<'db> ProtocolInterface<'db> {
other: Self,
relation: TypeRelation,
) -> bool {
let this_interface = self.inner(db);
let this_interface = self
.normalized_impl(db, &mut TypeVisitor::default())
.inner(db);
other.inner(db).iter().all(|(name, super_data)| {
this_interface
.get(name)
.is_some_and(|sub_data| sub_data.has_relation_to(db, super_data, relation))
})
other
.normalized_impl(db, &mut TypeVisitor::default())
.inner(db)
.iter()
.all(|(name, super_data)| {
this_interface
.get(name)
.is_some_and(|sub_data| sub_data.has_relation_to(db, super_data, relation))
})
}
/// Return `true` if the types of any of the members match the closure passed in.