|
118 | 118 | use PHPStan\PhpDoc\Tag\VarTag;
|
119 | 119 | use PHPStan\Reflection\Assertions;
|
120 | 120 | use PHPStan\Reflection\ClassReflection;
|
| 121 | +use PHPStan\Reflection\ExtendedMethodReflection; |
121 | 122 | use PHPStan\Reflection\FunctionReflection;
|
122 | 123 | use PHPStan\Reflection\InitializerExprTypeResolver;
|
123 | 124 | use PHPStan\Reflection\MethodReflection;
|
|
160 | 161 | use PHPStan\Type\StaticType;
|
161 | 162 | use PHPStan\Type\StaticTypeFactory;
|
162 | 163 | use PHPStan\Type\StringType;
|
| 164 | +use PHPStan\Type\ThisType; |
163 | 165 | use PHPStan\Type\Type;
|
164 | 166 | use PHPStan\Type\TypeCombinator;
|
165 | 167 | use PHPStan\Type\TypeTraverser;
|
@@ -2080,7 +2082,7 @@ static function (): void {
|
2080 | 2082 | if ($parametersAcceptor !== null) {
|
2081 | 2083 | $expr = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $expr) ?? $expr;
|
2082 | 2084 | }
|
2083 |
| - $result = $this->processArgs($stmt, $functionReflection, $parametersAcceptor, $expr->getArgs(), $scope, $nodeCallback, $context); |
| 2085 | + $result = $this->processArgs($stmt, $functionReflection, null, $parametersAcceptor, $expr->getArgs(), $scope, $nodeCallback, $context); |
2084 | 2086 | $scope = $result->getScope();
|
2085 | 2087 | $hasYield = $result->hasYield();
|
2086 | 2088 | $throwPoints = array_merge($throwPoints, $result->getThrowPoints());
|
@@ -2298,7 +2300,16 @@ static function (): void {
|
2298 | 2300 | if ($parametersAcceptor !== null) {
|
2299 | 2301 | $expr = ArgumentsNormalizer::reorderMethodArguments($parametersAcceptor, $expr) ?? $expr;
|
2300 | 2302 | }
|
2301 |
| - $result = $this->processArgs($stmt, $methodReflection, $parametersAcceptor, $expr->getArgs(), $scope, $nodeCallback, $context); |
| 2303 | + $result = $this->processArgs( |
| 2304 | + $stmt, |
| 2305 | + $methodReflection, |
| 2306 | + $methodReflection !== null ? $scope->getNakedMethod($calledOnType, $methodReflection->getName()) : null, |
| 2307 | + $parametersAcceptor, |
| 2308 | + $expr->getArgs(), |
| 2309 | + $scope, |
| 2310 | + $nodeCallback, |
| 2311 | + $context, |
| 2312 | + ); |
2302 | 2313 | $scope = $result->getScope();
|
2303 | 2314 |
|
2304 | 2315 | if ($methodReflection !== null) {
|
@@ -2457,7 +2468,7 @@ static function (): void {
|
2457 | 2468 | if ($parametersAcceptor !== null) {
|
2458 | 2469 | $expr = ArgumentsNormalizer::reorderStaticCallArguments($parametersAcceptor, $expr) ?? $expr;
|
2459 | 2470 | }
|
2460 |
| - $result = $this->processArgs($stmt, $methodReflection, $parametersAcceptor, $expr->getArgs(), $scope, $nodeCallback, $context, $closureBindScope ?? null); |
| 2471 | + $result = $this->processArgs($stmt, $methodReflection, null, $parametersAcceptor, $expr->getArgs(), $scope, $nodeCallback, $context, $closureBindScope ?? null); |
2461 | 2472 | $scope = $result->getScope();
|
2462 | 2473 | $scopeFunction = $scope->getFunction();
|
2463 | 2474 |
|
@@ -2792,7 +2803,7 @@ static function (): void {
|
2792 | 2803 | if ($parametersAcceptor !== null) {
|
2793 | 2804 | $expr = ArgumentsNormalizer::reorderNewArguments($parametersAcceptor, $expr) ?? $expr;
|
2794 | 2805 | }
|
2795 |
| - $result = $this->processArgs($stmt, $constructorReflection, $parametersAcceptor, $expr->getArgs(), $scope, $nodeCallback, $context); |
| 2806 | + $result = $this->processArgs($stmt, $constructorReflection, null, $parametersAcceptor, $expr->getArgs(), $scope, $nodeCallback, $context); |
2796 | 2807 | $scope = $result->getScope();
|
2797 | 2808 | $hasYield = $hasYield || $result->hasYield();
|
2798 | 2809 | $throwPoints = array_merge($throwPoints, $result->getThrowPoints());
|
@@ -3697,6 +3708,7 @@ private function processAttributeGroups(
|
3697 | 3708 | private function processArgs(
|
3698 | 3709 | Node\Stmt $stmt,
|
3699 | 3710 | $calleeReflection,
|
| 3711 | + ?ExtendedMethodReflection $nakedMethodReflection, |
3700 | 3712 | ?ParametersAcceptor $parametersAcceptor,
|
3701 | 3713 | array $args,
|
3702 | 3714 | MutatingScope $scope,
|
@@ -3821,7 +3833,25 @@ private function processArgs(
|
3821 | 3833 | }
|
3822 | 3834 | } elseif ($calleeReflection !== null && $calleeReflection->hasSideEffects()->yes()) {
|
3823 | 3835 | $argType = $scope->getType($arg->value);
|
3824 |
| - if (!$argType->isObject()->no() || !(new ResourceType())->isSuperTypeOf($argType)->no()) { |
| 3836 | + if (!$argType->isObject()->no()) { |
| 3837 | + $nakedReturnType = null; |
| 3838 | + if ($nakedMethodReflection !== null) { |
| 3839 | + $nakedParametersAcceptor = ParametersAcceptorSelector::selectFromArgs( |
| 3840 | + $scope, |
| 3841 | + $args, |
| 3842 | + $nakedMethodReflection->getVariants(), |
| 3843 | + $nakedMethodReflection->getNamedArgumentsVariants(), |
| 3844 | + ); |
| 3845 | + $nakedReturnType = $nakedParametersAcceptor->getReturnType(); |
| 3846 | + } |
| 3847 | + if ( |
| 3848 | + $nakedReturnType === null |
| 3849 | + || !(new ThisType($nakedMethodReflection->getDeclaringClass()))->isSuperTypeOf($nakedReturnType)->yes() |
| 3850 | + || $nakedMethodReflection->isPure()->no() |
| 3851 | + ) { |
| 3852 | + $scope = $scope->invalidateExpression($arg->value, true); |
| 3853 | + } |
| 3854 | + } elseif (!(new ResourceType())->isSuperTypeOf($argType)->no()) { |
3825 | 3855 | $scope = $scope->invalidateExpression($arg->value, true);
|
3826 | 3856 | }
|
3827 | 3857 | }
|
|
0 commit comments