diff --git a/src/Type/TypeCombinator.php b/src/Type/TypeCombinator.php index 454ca9717f..96a0d78466 100644 --- a/src/Type/TypeCombinator.php +++ b/src/Type/TypeCombinator.php @@ -95,6 +95,9 @@ public static function containsNull(Type $type): bool public static function union(Type ...$types): Type { $typesCount = count($types); + if ($typesCount === 0) { + return new NeverType(); + } $benevolentTypes = []; $benevolentUnionObject = null; @@ -126,6 +129,10 @@ public static function union(Type ...$types): Type $typesCount += count($typesInner) - 1; } + if ($typesCount === 1) { + return $types[0]; + } + $arrayTypes = []; $arrayAccessoryTypes = []; $scalarTypes = [];