diff --git a/src/Type/TypeCombinator.php b/src/Type/TypeCombinator.php index 7da4704d5a..67658e9d63 100644 --- a/src/Type/TypeCombinator.php +++ b/src/Type/TypeCombinator.php @@ -151,10 +151,23 @@ public static function union(Type ...$types): Type $alreadyNormalized = []; $alreadyNormalizedCounter = 0; + $containsNonNever = false; + $benevolentTypes = []; $benevolentUnionObject = null; // transform A | (B | C) to A | B | C for ($i = 0; $i < $typesCount; $i++) { + // transform A | never to A + if ($types[$i] instanceof NeverType) { + if ($containsNonNever) { + array_splice($types, $i--, 1); + $typesCount--; + continue; + } + } else { + $containsNonNever = true; + } + if ($types[$i] instanceof BenevolentUnionType) { if ($types[$i] instanceof TemplateBenevolentUnionType && $benevolentUnionObject === null) { $benevolentUnionObject = $types[$i];