diff --git a/src/Type/UnionType.php b/src/Type/UnionType.php index 011cdec9389..40020ddca0c 100644 --- a/src/Type/UnionType.php +++ b/src/Type/UnionType.php @@ -1412,8 +1412,17 @@ private function notBenevolentUnionResults(callable $getResult): TrinaryLogic protected function unionTypes(callable $getType): Type { $newTypes = []; + $changed = false; foreach ($this->types as $type) { - $newTypes[] = $getType($type); + $newType = $getType($type); + if ($newType !== $type) { + $changed = true; + } + $newTypes[] = $newType; + } + + if (!$changed) { + return $this; } return TypeCombinator::union(...$newTypes);