From 1968678fe50f7fc46ffd3679814763723c2f8fbb Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 27 Dec 2025 14:18:48 +0100 Subject: [PATCH] TypeCombinator: Remove never types early --- src/Type/TypeCombinator.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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];