fix disjointness between class-literal and generic-alias

This commit is contained in:
Ibraheem Ahmed 2025-12-10 14:46:09 -05:00
parent 7dfe6e0f7f
commit e4e1ff21d2
2 changed files with 21 additions and 10 deletions

View File

@ -684,9 +684,8 @@ class GenericClass[T]:
x: T # invariant x: T # invariant
static_assert(not is_disjoint_from(TypeOf[GenericClass], type[GenericClass])) static_assert(not is_disjoint_from(TypeOf[GenericClass], type[GenericClass]))
# TODO: these should not error static_assert(not is_disjoint_from(TypeOf[GenericClass[int]], type[GenericClass]))
static_assert(not is_disjoint_from(TypeOf[GenericClass[int]], type[GenericClass])) # error: [static-assert-error] static_assert(not is_disjoint_from(TypeOf[GenericClass], type[GenericClass[int]]))
static_assert(not is_disjoint_from(TypeOf[GenericClass], type[GenericClass[int]])) # error: [static-assert-error]
static_assert(not is_disjoint_from(TypeOf[GenericClass[int]], type[GenericClass[int]])) static_assert(not is_disjoint_from(TypeOf[GenericClass[int]], type[GenericClass[int]]))
static_assert(is_disjoint_from(TypeOf[GenericClass[str]], type[GenericClass[int]])) static_assert(is_disjoint_from(TypeOf[GenericClass[str]], type[GenericClass[int]]))
@ -694,19 +693,17 @@ class GenericClassIntBound[T: int]:
x: T # invariant x: T # invariant
static_assert(not is_disjoint_from(TypeOf[GenericClassIntBound], type[GenericClassIntBound])) static_assert(not is_disjoint_from(TypeOf[GenericClassIntBound], type[GenericClassIntBound]))
# TODO: these should not error static_assert(not is_disjoint_from(TypeOf[GenericClassIntBound[int]], type[GenericClassIntBound]))
static_assert(not is_disjoint_from(TypeOf[GenericClassIntBound[int]], type[GenericClassIntBound])) # error: [static-assert-error] static_assert(not is_disjoint_from(TypeOf[GenericClassIntBound], type[GenericClassIntBound[int]]))
static_assert(not is_disjoint_from(TypeOf[GenericClassIntBound], type[GenericClassIntBound[int]])) # error: [static-assert-error]
static_assert(not is_disjoint_from(TypeOf[GenericClassIntBound[int]], type[GenericClassIntBound[int]])) static_assert(not is_disjoint_from(TypeOf[GenericClassIntBound[int]], type[GenericClassIntBound[int]]))
@final @final
class GenericFinalClass[T]: class GenericFinalClass[T]:
x: T # invariant x: T # invariant
# TODO: these should not error static_assert(not is_disjoint_from(TypeOf[GenericFinalClass], type[GenericFinalClass]))
static_assert(not is_disjoint_from(TypeOf[GenericFinalClass], type[GenericFinalClass])) # error: [static-assert-error] static_assert(not is_disjoint_from(TypeOf[GenericFinalClass[int]], type[GenericFinalClass]))
static_assert(not is_disjoint_from(TypeOf[GenericFinalClass[int]], type[GenericFinalClass])) # error: [static-assert-error] static_assert(not is_disjoint_from(TypeOf[GenericFinalClass], type[GenericFinalClass[int]]))
static_assert(not is_disjoint_from(TypeOf[GenericFinalClass], type[GenericFinalClass[int]])) # error: [static-assert-error]
static_assert(not is_disjoint_from(TypeOf[GenericFinalClass[int]], type[GenericFinalClass[int]])) static_assert(not is_disjoint_from(TypeOf[GenericFinalClass[int]], type[GenericFinalClass[int]]))
static_assert(is_disjoint_from(TypeOf[GenericFinalClass[str]], type[GenericFinalClass[int]])) static_assert(is_disjoint_from(TypeOf[GenericFinalClass[str]], type[GenericFinalClass[int]]))
``` ```

View File

@ -3554,6 +3554,20 @@ impl<'db> Type<'db> {
}) })
} }
(Type::ClassLiteral(class_literal), other @ Type::GenericAlias(_))
| (other @ Type::GenericAlias(_), Type::ClassLiteral(class_literal)) => class_literal
.default_specialization(db)
.into_generic_alias()
.when_none_or(|alias| {
other.is_disjoint_from_impl(
db,
Type::GenericAlias(alias),
inferable,
disjointness_visitor,
relation_visitor,
)
}),
(Type::SubclassOf(subclass_of_ty), Type::ClassLiteral(class_b)) (Type::SubclassOf(subclass_of_ty), Type::ClassLiteral(class_b))
| (Type::ClassLiteral(class_b), Type::SubclassOf(subclass_of_ty)) => { | (Type::ClassLiteral(class_b), Type::SubclassOf(subclass_of_ty)) => {
match subclass_of_ty.subclass_of() { match subclass_of_ty.subclass_of() {