Skip to content

Commit 2a4354d

Browse files
committed
wip
1 parent 418647d commit 2a4354d

File tree

8 files changed

+3326
-5
lines changed

8 files changed

+3326
-5
lines changed

closure.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
array_find(
4+
['foo' => 1, 'bar' => 2],
5+
function(int $value, string $key) {
6+
return $key;
7+
},
8+
);

foo.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
class Foo
4+
{
5+
6+
public function doFoo(DateTimeImmutable $d): void
7+
{
8+
$a = $d->format('j. n. Y');
9+
}
10+
11+
}

foob.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
function doFoo(A $a)
4+
{
5+
6+
}

log.txt

Lines changed: 3286 additions & 0 deletions
Large diffs are not rendered by default.

src/Analyser/MutatingScope.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,7 +2922,7 @@ 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];
@@ -2945,7 +2945,11 @@ public function pushInFunctionCall($reflection, ?ParameterReflection $parameter)
29452945
$this->parentScope,
29462946
$this->nativeTypesPromoted,
29472947
);
2948-
$functionScope->resolvedTypes = $this->resolvedTypes;
2948+
2949+
if ($rememberTypes) {
2950+
$functionScope->resolvedTypes = $this->resolvedTypes;
2951+
}
2952+
29492953
return $functionScope;
29502954
}
29512955

@@ -2972,7 +2976,9 @@ public function popInFunctionCall(): self
29722976
$this->parentScope,
29732977
$this->nativeTypesPromoted,
29742978
);
2979+
29752980
$parentScope->resolvedTypes = $this->resolvedTypes;
2981+
29762982
return $parentScope;
29772983
}
29782984

src/Analyser/NodeScopeResolver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5604,7 +5604,8 @@ private function processArgs(
56045604
}
56055605

56065606
if ($calleeReflection !== null) {
5607-
$scope = $scope->pushInFunctionCall($calleeReflection, $parameter);
5607+
$scope = $scope->pushInFunctionCall($calleeReflection, $parameter, true);
5608+
$pushTimeScope = $scope;
56085609
}
56095610

56105611
$originalArg = $arg->getAttribute(ArgumentsNormalizer::ORIGINAL_ARG_ATTRIBUTE) ?? $arg;

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+
$scope = $scope->pushInFunctionCall(null, $parameter, true);
503+
$pushTimeScope = $scope;
503504
}
504505

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

src/Rules/FunctionCallParametersCheck.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ 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);
324+
$pushTimeScope = $scope;
323325
}
324326
$argumentValueType = $scope->getType($argumentValue);
325327

0 commit comments

Comments
 (0)