Skip to content

Commit 8536a41

Browse files
authored
Prevent unnecessary re-creation of benevolent union types (#6119)
1 parent 1501355 commit 8536a41

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/Type/BenevolentUnionType.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,27 @@ public function describe(VerbosityLevel $level): string
4646

4747
protected function unionTypes(callable $getType): Type
4848
{
49+
$changed = false;
50+
4951
$resultTypes = [];
5052
foreach ($this->getTypes() as $type) {
5153
$result = $getType($type);
5254
if ($result instanceof ErrorType) {
55+
$changed = true;
5356
continue;
5457
}
5558

59+
if ($result !== $type) {
60+
$changed = true;
61+
}
62+
5663
$resultTypes[] = $result;
5764
}
5865

66+
if (!$changed) {
67+
return $this;
68+
}
69+
5970
if (count($resultTypes) === 0) {
6071
return new ErrorType();
6172
}

0 commit comments

Comments
 (0)