experiment: sort unions in cycle recovery functions

This commit is contained in:
Shunsuke Shibayama 2025-12-12 15:23:47 +09:00
parent b575dcd6b8
commit 74d3ad6ef4
2 changed files with 2 additions and 9 deletions

View File

@ -14194,7 +14194,7 @@ impl<'db> UnionType<'db> {
nested: bool,
) -> Option<Type<'db>> {
let mut builder = UnionBuilder::new(db)
.order_elements(false)
.order_elements(true)
.unpack_aliases(false)
.cycle_recovery(true)
.recursively_defined(self.recursively_defined(db));

View File

@ -38,7 +38,6 @@
//! unnecessary `is_subtype_of` checks.
use crate::types::enums::{enum_member_literals, enum_metadata};
use crate::types::type_ordering::union_or_intersection_elements_ordering;
use crate::types::{
BytesLiteralType, IntersectionType, KnownClass, StringLiteralType, Type,
TypeVarBoundOrConstraints, UnionType, structural_type_ordering,
@ -652,13 +651,7 @@ impl<'db> UnionBuilder<'db> {
}
}
if self.order_elements {
types.sort_unstable_by(|l, r| {
if self.recursively_defined.is_yes() {
structural_type_ordering(self.db, l, r)
} else {
union_or_intersection_elements_ordering(self.db, l, r)
}
});
types.sort_unstable_by(|l, r| structural_type_ordering(self.db, l, r));
}
match types.len() {
0 => None,