From 109bf999b8791f512f2fe82b026ccd67d1f152a2 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Sun, 12 Sep 2021 10:20:56 +0200 Subject: [PATCH] Pass-by-ref argument type passed to callable should be mixed after calling the callable --- src/Analyser/NodeScopeResolver.php | 8 +++++ .../Analyser/NodeScopeResolverTest.php | 1 + tests/PHPStan/Analyser/data/bug-5615.php | 29 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 tests/PHPStan/Analyser/data/bug-5615.php diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 88766bd69c..fcc8275ecc 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -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(); diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 87d5a2ff20..5b93dd30c6 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -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'); } /** diff --git a/tests/PHPStan/Analyser/data/bug-5615.php b/tests/PHPStan/Analyser/data/bug-5615.php new file mode 100644 index 0000000000..5c8f8027fb --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-5615.php @@ -0,0 +1,29 @@ +