From effad95da555c2b6c7b305178a221e84c831df61 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Wed, 13 Mar 2024 10:14:26 +0100 Subject: [PATCH] Support for conditional types in `@param-out` --- src/Reflection/ResolvedFunctionVariant.php | 13 ++++---- .../Analyser/NodeScopeResolverTest.php | 1 + tests/PHPStan/Analyser/data/bug-10699.php | 30 +++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 tests/PHPStan/Analyser/data/bug-10699.php diff --git a/src/Reflection/ResolvedFunctionVariant.php b/src/Reflection/ResolvedFunctionVariant.php index b914ab7662..b618cf3928 100644 --- a/src/Reflection/ResolvedFunctionVariant.php +++ b/src/Reflection/ResolvedFunctionVariant.php @@ -84,11 +84,14 @@ function (ParameterReflectionWithPhpDocs $param): ParameterReflectionWithPhpDocs $paramOutType = $param->getOutType(); if ($paramOutType !== null) { - $paramOutType = TemplateTypeHelper::resolveTemplateTypes( - $paramOutType, - $this->resolvedTemplateTypeMap, - $this->callSiteVarianceMap, - TemplateTypeVariance::createCovariant(), + $paramOutType = TypeUtils::resolveLateResolvableTypes( + TemplateTypeHelper::resolveTemplateTypes( + $this->resolveConditionalTypesForParameter($paramOutType), + $this->resolvedTemplateTypeMap, + $this->callSiteVarianceMap, + TemplateTypeVariance::createCovariant(), + ), + false, ); } diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index c9a3fc9fff..e42e662738 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -333,6 +333,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4500.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4504.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4436.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10699.php'); yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Properties/data/bug-3777.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-2549.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-1945.php'); diff --git a/tests/PHPStan/Analyser/data/bug-10699.php b/tests/PHPStan/Analyser/data/bug-10699.php new file mode 100644 index 0000000000..1c75b5b13c --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-10699.php @@ -0,0 +1,30 @@ +