Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -2922,12 +2922,12 @@ public function hasExpressionType(Expr $node): TrinaryLogic
/**
* @param MethodReflection|FunctionReflection|null $reflection
*/
public function pushInFunctionCall($reflection, ?ParameterReflection $parameter): self
public function pushInFunctionCall($reflection, ?ParameterReflection $parameter, bool $rememberTypes): self
{
$stack = $this->inFunctionCallsStack;
$stack[] = [$reflection, $parameter];

return $this->scopeFactory->create(
$functionScope = $this->scopeFactory->create(
$this->context,
$this->isDeclareStrictTypes(),
$this->getFunction(),
Expand All @@ -2945,14 +2945,20 @@ public function pushInFunctionCall($reflection, ?ParameterReflection $parameter)
$this->parentScope,
$this->nativeTypesPromoted,
);

if ($rememberTypes) {
$functionScope->resolvedTypes = $this->resolvedTypes;
}

return $functionScope;
}

public function popInFunctionCall(): self
{
$stack = $this->inFunctionCallsStack;
array_pop($stack);

return $this->scopeFactory->create(
$parentScope = $this->scopeFactory->create(
$this->context,
$this->isDeclareStrictTypes(),
$this->getFunction(),
Expand All @@ -2970,6 +2976,10 @@ public function popInFunctionCall(): self
$this->parentScope,
$this->nativeTypesPromoted,
);

$parentScope->resolvedTypes = $this->resolvedTypes;

return $parentScope;
}

/** @api */
Expand Down
5 changes: 3 additions & 2 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5603,11 +5603,12 @@ private function processArgs(
}
}

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

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

$originalScope = $scope;
Expand Down
3 changes: 2 additions & 1 deletion src/Reflection/ParametersAcceptorSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ public static function selectFromArgs(
}

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

$type = $scope->getType($originalArg->value);
Expand Down
3 changes: 2 additions & 1 deletion src/Rules/FunctionCallParametersCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ public function check(

if ($argumentValueType === null) {
if ($scope instanceof MutatingScope) {
$scope = $scope->pushInFunctionCall(null, $parameter);
$rememberTypes = !$argumentValue instanceof Expr\Closure && !$argumentValue instanceof Expr\ArrowFunction;
$scope = $scope->pushInFunctionCall(null, $parameter, $rememberTypes);
}
$argumentValueType = $scope->getType($argumentValue);

Expand Down
Loading