Skip to content

Commit

Permalink
Pass-by-ref argument type passed to callable should be mixed after ca…
Browse files Browse the repository at this point in the history
…lling the callable
  • Loading branch information
ondrejmirtes committed Sep 12, 2021
1 parent 0249e6d commit 109bf99
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,14 @@ function (MutatingScope $scope) use ($expr, $nodeCallback, $context): Expression
$functionReflection = null;
$throwPoints = [];
if ($expr->name instanceof Expr) {
$nameType = $scope->getType($expr->name);
if ($nameType->isCallable()->yes()) {
$parametersAcceptor = ParametersAcceptorSelector::selectFromArgs(
$scope,
$expr->args,
$nameType->getCallableParametersAcceptors($scope)
);
}
$nameResult = $this->processExprNode($expr->name, $scope, $nodeCallback, $context->enterDeep());
$throwPoints = $nameResult->getThrowPoints();
$scope = $nameResult->getScope();
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ public function dataFileAsserts(): iterable

yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-1870.php');
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Methods/data/bug-5562.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5615.php');
}

/**
Expand Down
29 changes: 29 additions & 0 deletions tests/PHPStan/Analyser/data/bug-5615.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Bug5615;

use function PHPStan\Testing\assertType;

class Foo
{

public function doFoo(): void
{
$cb = function (bool &$save): void {

};
$save = true;
$cb($save);
assertType('mixed', $save);
}

/**
* @param callable(bool &$save): void $call
*/
function get(callable $call) {
$save = true;
$call($save);
assertType('mixed', $save);
}

}

0 comments on commit 109bf99

Please sign in to comment.