Skip to content

Commit 23918f6

Browse files
authored
Fix @param-out on methods
1 parent b4434ee commit 23918f6

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

src/Reflection/Type/CallbackUnresolvedMethodPrototypeReflection.php

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
use PHPStan\Reflection\ExtendedMethodReflection;
88
use PHPStan\Reflection\FunctionVariant;
99
use PHPStan\Reflection\ParameterReflection;
10+
use PHPStan\Reflection\ParameterReflectionWithPhpDocs;
1011
use PHPStan\Reflection\ParametersAcceptor;
1112
use PHPStan\Reflection\Php\DummyParameter;
13+
use PHPStan\Reflection\Php\DummyParameterWithPhpDocs;
1214
use PHPStan\Reflection\ResolvedMethodReflection;
1315
use PHPStan\Type\Type;
1416
use function array_map;
@@ -83,14 +85,33 @@ private function transformMethodWithStaticType(ClassReflection $declaringClass,
8385
$variants = array_map(fn (ParametersAcceptor $acceptor): ParametersAcceptor => new FunctionVariant(
8486
$acceptor->getTemplateTypeMap(),
8587
$acceptor->getResolvedTemplateTypeMap(),
86-
array_map(fn (ParameterReflection $parameter): ParameterReflection => new DummyParameter(
87-
$parameter->getName(),
88-
$this->transformStaticType($parameter->getType()),
89-
$parameter->isOptional(),
90-
$parameter->passedByReference(),
91-
$parameter->isVariadic(),
92-
$parameter->getDefaultValue(),
93-
), $acceptor->getParameters()),
88+
array_map(
89+
function (ParameterReflection $parameter): ParameterReflection {
90+
if ($parameter instanceof ParameterReflectionWithPhpDocs) {
91+
return new DummyParameterWithPhpDocs(
92+
$parameter->getName(),
93+
$this->transformStaticType($parameter->getType()),
94+
$parameter->isOptional(),
95+
$parameter->passedByReference(),
96+
$parameter->isVariadic(),
97+
$parameter->getDefaultValue(),
98+
$parameter->getNativeType(),
99+
$parameter->getPhpDocType(),
100+
$parameter->getOutType(),
101+
);
102+
}
103+
104+
return new DummyParameter(
105+
$parameter->getName(),
106+
$this->transformStaticType($parameter->getType()),
107+
$parameter->isOptional(),
108+
$parameter->passedByReference(),
109+
$parameter->isVariadic(),
110+
$parameter->getDefaultValue(),
111+
);
112+
},
113+
$acceptor->getParameters(),
114+
),
94115
$acceptor->isVariadic(),
95116
$this->transformStaticType($acceptor->getReturnType()),
96117
), $method->getVariants());

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,7 @@ public function dataFileAsserts(): iterable
11321132
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8361.php');
11331133
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8373.php');
11341134
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Functions/data/bug-8389.php');
1135+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8421.php');
11351136
}
11361137

11371138
/**
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug8421;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
final class Foo {
8+
/** @param-out int $i */
9+
final public function foo(mixed &$i): void {
10+
$i = 5;
11+
}
12+
final public function bar(): void {
13+
$this->foo($a);
14+
assertType('int', $a);
15+
}
16+
}

0 commit comments

Comments
 (0)