Skip to content

Commit 5c67ca8

Browse files
authored
Remember resolved types after pushInFunctionCall
1 parent e8f9992 commit 5c67ca8

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

src/Analyser/MutatingScope.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,12 +2922,12 @@ public function hasExpressionType(Expr $node): TrinaryLogic
29222922
/**
29232923
* @param MethodReflection|FunctionReflection|null $reflection
29242924
*/
2925-
public function pushInFunctionCall($reflection, ?ParameterReflection $parameter): self
2925+
public function pushInFunctionCall($reflection, ?ParameterReflection $parameter, bool $rememberTypes): self
29262926
{
29272927
$stack = $this->inFunctionCallsStack;
29282928
$stack[] = [$reflection, $parameter];
29292929

2930-
return $this->scopeFactory->create(
2930+
$functionScope = $this->scopeFactory->create(
29312931
$this->context,
29322932
$this->isDeclareStrictTypes(),
29332933
$this->getFunction(),
@@ -2945,14 +2945,20 @@ public function pushInFunctionCall($reflection, ?ParameterReflection $parameter)
29452945
$this->parentScope,
29462946
$this->nativeTypesPromoted,
29472947
);
2948+
2949+
if ($rememberTypes) {
2950+
$functionScope->resolvedTypes = $this->resolvedTypes;
2951+
}
2952+
2953+
return $functionScope;
29482954
}
29492955

29502956
public function popInFunctionCall(): self
29512957
{
29522958
$stack = $this->inFunctionCallsStack;
29532959
array_pop($stack);
29542960

2955-
return $this->scopeFactory->create(
2961+
$parentScope = $this->scopeFactory->create(
29562962
$this->context,
29572963
$this->isDeclareStrictTypes(),
29582964
$this->getFunction(),
@@ -2970,6 +2976,10 @@ public function popInFunctionCall(): self
29702976
$this->parentScope,
29712977
$this->nativeTypesPromoted,
29722978
);
2979+
2980+
$parentScope->resolvedTypes = $this->resolvedTypes;
2981+
2982+
return $parentScope;
29732983
}
29742984

29752985
/** @api */

src/Analyser/NodeScopeResolver.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5603,11 +5603,12 @@ private function processArgs(
56035603
}
56045604
}
56055605

5606+
$originalArg = $arg->getAttribute(ArgumentsNormalizer::ORIGINAL_ARG_ATTRIBUTE) ?? $arg;
56065607
if ($calleeReflection !== null) {
5607-
$scope = $scope->pushInFunctionCall($calleeReflection, $parameter);
5608+
$rememberTypes = !$originalArg->value instanceof Expr\Closure && !$originalArg->value instanceof Expr\ArrowFunction;
5609+
$scope = $scope->pushInFunctionCall($calleeReflection, $parameter, $rememberTypes);
56085610
}
56095611

5610-
$originalArg = $arg->getAttribute(ArgumentsNormalizer::ORIGINAL_ARG_ATTRIBUTE) ?? $arg;
56115612
$this->callNodeCallback($nodeCallback, $originalArg, $scope, $storage);
56125613

56135614
$originalScope = $scope;

src/Reflection/ParametersAcceptorSelector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ public static function selectFromArgs(
499499
}
500500

501501
if ($parameter !== null && $scope instanceof MutatingScope) {
502-
$scope = $scope->pushInFunctionCall(null, $parameter);
502+
$rememberTypes = !$originalArg->value instanceof Node\Expr\Closure && !$originalArg->value instanceof Node\Expr\ArrowFunction;
503+
$scope = $scope->pushInFunctionCall(null, $parameter, $rememberTypes);
503504
}
504505

505506
$type = $scope->getType($originalArg->value);

src/Rules/FunctionCallParametersCheck.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ public function check(
319319

320320
if ($argumentValueType === null) {
321321
if ($scope instanceof MutatingScope) {
322-
$scope = $scope->pushInFunctionCall(null, $parameter);
322+
$rememberTypes = !$argumentValue instanceof Expr\Closure && !$argumentValue instanceof Expr\ArrowFunction;
323+
$scope = $scope->pushInFunctionCall(null, $parameter, $rememberTypes);
323324
}
324325
$argumentValueType = $scope->getType($argumentValue);
325326

0 commit comments

Comments
 (0)