From 095fe1d339fcd0af350814566ec1ac245192f872 Mon Sep 17 00:00:00 2001 From: Yohta Kimura Date: Thu, 22 Dec 2022 01:21:13 +0900 Subject: [PATCH] fix flatten --- src/Type/TypeCombinator.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Type/TypeCombinator.php b/src/Type/TypeCombinator.php index 142184dd5f5..ca6682034bc 100644 --- a/src/Type/TypeCombinator.php +++ b/src/Type/TypeCombinator.php @@ -209,10 +209,11 @@ public static function union(Type ...$types): Type } if ($scalarTypes !== []) { - if (count($scalarTypes) === 1) { - $types[] = $scalarTypes[array_key_first($scalarTypes)][0]; + $flattenTypes = array_merge(...array_values($scalarTypes)); + if (count($flattenTypes) === 1) { + $types[] = $flattenTypes[0]; } else { - $types[] = new UnionType(array_merge(...array_values($scalarTypes)), true); + $types[] = new UnionType($flattenTypes, true); } }