diff --git a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php index f31b7d0fe..3db3e8ada 100644 --- a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php @@ -1642,7 +1642,7 @@ class SimpleAssertionReconciler extends \Psalm\Type\Reconciler $existing_var_atomic_types = $existing_var_type->getAtomicTypes(); - if ($existing_var_type->hasMixed() || $existing_var_type->hasTemplate()) { + if ($existing_var_type->hasMixed()) { return Type::getArray(); } @@ -1666,6 +1666,24 @@ class SimpleAssertionReconciler extends \Psalm\Type\Reconciler $array_types[] = new TArray($clone_type->type_params); + $did_remove_type = true; + } elseif ($type instanceof TTemplateParam) { + if ($type->as->hasArray() || $type->as->hasMixed()) { + $type = clone $type; + + $type->as = self::reconcileArray( + $type->as, + null, + false, + null, + $suppressed_issues, + $failed_reconciliation, + $is_equality + ); + + $array_types[] = $type; + } + $did_remove_type = true; } else { $did_remove_type = true; diff --git a/tests/Template/ConditionalReturnTypeTest.php b/tests/Template/ConditionalReturnTypeTest.php index 3d096863c..d849c25fc 100644 --- a/tests/Template/ConditionalReturnTypeTest.php +++ b/tests/Template/ConditionalReturnTypeTest.php @@ -653,6 +653,21 @@ class ConditionalReturnTypeTest extends TestCase '$expect_mixed_from_literal' => 'mixed', ] ], + 'isArryCheckOnTemplate' => [ + ' + * @param TResult $result + * @return (TResult is array ? list : string) + */ + function recursion($result) { + if (\is_array($result)) { + return $result; + } + + return strtoupper($result); + }' + ], ]; } }