Skip to content

Commit

Permalink
Make @param-out work even if it is the only conditional type in a f…
Browse files Browse the repository at this point in the history
…unction signature
  • Loading branch information
ondrejmirtes committed Mar 13, 2024
1 parent 709f1d0 commit 787c1e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Reflection/ParametersAcceptorSelector.php
Expand Up @@ -267,6 +267,14 @@ private static function hasAcceptorTemplateOrLateResolvableType(ParametersAccept
}

foreach ($acceptor->getParameters() as $parameter) {
if (
$parameter instanceof ParameterReflectionWithPhpDocs
&& $parameter->getOutType() !== null
&& self::hasTemplateOrLateResolvableType($parameter->getOutType())
) {
return true;
}

if (!self::hasTemplateOrLateResolvableType($parameter->getType())) {
continue;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/PHPStan/Analyser/data/bug-10699.php
Expand Up @@ -28,3 +28,22 @@ function (): void {
assertType('20', $res);
assertType('20', $out);
};

/**
* @param int $flags
* @param mixed $out
*
* @param-out ($flags is 2 ? 20 : 10) $out
*/
function test2(int $flags, &$out): void
{
$out = $flags === 2 ? 20 : 10;
}

function (): void {
test2(1, $out);
assertType('10', $out);

test2(2, $out);
assertType('20', $out);
};

0 comments on commit 787c1e2

Please sign in to comment.