Skip to content

Commit 109bf99

Browse files
committed
Pass-by-ref argument type passed to callable should be mixed after calling the callable
1 parent 0249e6d commit 109bf99

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,6 +1828,14 @@ function (MutatingScope $scope) use ($expr, $nodeCallback, $context): Expression
18281828
$functionReflection = null;
18291829
$throwPoints = [];
18301830
if ($expr->name instanceof Expr) {
1831+
$nameType = $scope->getType($expr->name);
1832+
if ($nameType->isCallable()->yes()) {
1833+
$parametersAcceptor = ParametersAcceptorSelector::selectFromArgs(
1834+
$scope,
1835+
$expr->args,
1836+
$nameType->getCallableParametersAcceptors($scope)
1837+
);
1838+
}
18311839
$nameResult = $this->processExprNode($expr->name, $scope, $nodeCallback, $context->enterDeep());
18321840
$throwPoints = $nameResult->getThrowPoints();
18331841
$scope = $nameResult->getScope();

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ public function dataFileAsserts(): iterable
501501

502502
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-1870.php');
503503
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Methods/data/bug-5562.php');
504+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5615.php');
504505
}
505506

506507
/**
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Bug5615;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Foo
8+
{
9+
10+
public function doFoo(): void
11+
{
12+
$cb = function (bool &$save): void {
13+
14+
};
15+
$save = true;
16+
$cb($save);
17+
assertType('mixed', $save);
18+
}
19+
20+
/**
21+
* @param callable(bool &$save): void $call
22+
*/
23+
function get(callable $call) {
24+
$save = true;
25+
$call($save);
26+
assertType('mixed', $save);
27+
}
28+
29+
}

0 commit comments

Comments
 (0)