Skip to content

Commit 787c1e2

Browse files
committed
Make @param-out work even if it is the only conditional type in a function signature
1 parent 709f1d0 commit 787c1e2

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/Reflection/ParametersAcceptorSelector.php

+8
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@ private static function hasAcceptorTemplateOrLateResolvableType(ParametersAccept
267267
}
268268

269269
foreach ($acceptor->getParameters() as $parameter) {
270+
if (
271+
$parameter instanceof ParameterReflectionWithPhpDocs
272+
&& $parameter->getOutType() !== null
273+
&& self::hasTemplateOrLateResolvableType($parameter->getOutType())
274+
) {
275+
return true;
276+
}
277+
270278
if (!self::hasTemplateOrLateResolvableType($parameter->getType())) {
271279
continue;
272280
}

tests/PHPStan/Analyser/data/bug-10699.php

+19
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,22 @@ function (): void {
2828
assertType('20', $res);
2929
assertType('20', $out);
3030
};
31+
32+
/**
33+
* @param int $flags
34+
* @param mixed $out
35+
*
36+
* @param-out ($flags is 2 ? 20 : 10) $out
37+
*/
38+
function test2(int $flags, &$out): void
39+
{
40+
$out = $flags === 2 ? 20 : 10;
41+
}
42+
43+
function (): void {
44+
test2(1, $out);
45+
assertType('10', $out);
46+
47+
test2(2, $out);
48+
assertType('20', $out);
49+
};

0 commit comments

Comments
 (0)