[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.
This commit is contained in:
Claude
2025-12-19 15:17:54 +00:00
committed by Zanie Blue
parent 7b6d0a90bc
commit 6a2f78786a

View File

@@ -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 {