diff --git a/src/Psalm/Internal/Type/TypeExpander.php b/src/Psalm/Internal/Type/TypeExpander.php index 6a5215222..bbfbc5b37 100644 --- a/src/Psalm/Internal/Type/TypeExpander.php +++ b/src/Psalm/Internal/Type/TypeExpander.php @@ -77,8 +77,6 @@ class TypeExpander ): Union { $new_return_type_parts = []; - $had_split_values = false; - foreach ($return_type->getAtomicTypes() as $return_type_part) { $parts = self::expandAtomic( $codebase, @@ -94,21 +92,13 @@ class TypeExpander $throw_on_unresolvable_constant, ); - if ($return_type_part instanceof TTypeAlias || count($parts) > 1) { - $had_split_values = true; - } - $new_return_type_parts = [...$new_return_type_parts, ...$parts]; } - if ($had_split_values) { - $fleshed_out_type = TypeCombiner::combine( - $new_return_type_parts, - $codebase, - ); - } else { - $fleshed_out_type = new Union($new_return_type_parts); - } + $fleshed_out_type = TypeCombiner::combine( + $new_return_type_parts, + $codebase, + ); $fleshed_out_type->from_docblock = $return_type->from_docblock; $fleshed_out_type->ignore_nullable_issues = $return_type->ignore_nullable_issues; diff --git a/tests/TypeAnnotationTest.php b/tests/TypeAnnotationTest.php index ad4fbf692..8cd1fb218 100644 --- a/tests/TypeAnnotationTest.php +++ b/tests/TypeAnnotationTest.php @@ -771,6 +771,38 @@ class TypeAnnotationTest extends TestCase '$output===' => 'array{phone: string}', ], ], + 'combineAliasOfArrayAndArrayCorrectly' => [ + 'code' => '|D $_doesNotWork + */ + public function doesNotWork($_doesNotWork): void { + /** @psalm-check-type-exact $_doesNotWork = D */; + } + }', + ], ]; }