From 6a2f78786a9cfe07e5f0c8571eacf876120bebdf Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 19 Dec 2025 15:17:54 +0000 Subject: [PATCH] [ty] Fix sub-union optimization to require both flags be No The optimization condition checked if `recursively_defined` flags matched, which would apply when both are Yes. However, unions with recursively_defined=Yes may have been built during cycle_recovery where simplification is incomplete. Change the condition to require both builder and union have recursively_defined=No, ensuring the optimization only applies to unions that are definitely fully simplified. --- crates/ty_python_semantic/src/types/builder.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/ty_python_semantic/src/types/builder.rs b/crates/ty_python_semantic/src/types/builder.rs index 5709779da4..12374faa87 100644 --- a/crates/ty_python_semantic/src/types/builder.rs +++ b/crates/ty_python_semantic/src/types/builder.rs @@ -337,10 +337,12 @@ impl<'db> UnionBuilder<'db> { // Capture the current element count to avoid comparing union elements against each other. // The union has already been simplified, so its elements don't need redundancy checks // between themselves, only against pre-existing elements. However, we only apply this - // optimization when not in cycle recovery AND the union's recursively_defined status - // matches the builder's, ensuring we're in a consistent context. + // optimization when not in cycle recovery AND both the builder and union have + // recursively_defined=No (indicating neither is involved in recursive type definitions + // where simplification might be incomplete). let batch_start = if !self.cycle_recovery - && self.recursively_defined == union.recursively_defined(self.db) + && self.recursively_defined == RecursivelyDefined::No + && union.recursively_defined(self.db) == RecursivelyDefined::No { Some(self.elements.len()) } else {