diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 32c4e7e638..e393c15cce 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -3798,15 +3798,24 @@ private function processArgs( $assignByReference = false; $parameter = null; $parameterType = null; + $parameterNativeType = null; if (isset($parameters) && $parametersAcceptor !== null) { if (isset($parameters[$i])) { $assignByReference = $parameters[$i]->passedByReference()->createsNewVariable(); $parameterType = $parameters[$i]->getType(); + + if ($parameters[$i] instanceof ParameterReflectionWithPhpDocs) { + $parameterNativeType = $parameters[$i]->getNativeType(); + } $parameter = $parameters[$i]; } elseif (count($parameters) > 0 && $parametersAcceptor->isVariadic()) { $lastParameter = $parameters[count($parameters) - 1]; $assignByReference = $lastParameter->passedByReference()->createsNewVariable(); $parameterType = $lastParameter->getType(); + + if ($lastParameter instanceof ParameterReflectionWithPhpDocs) { + $parameterNativeType = $lastParameter->getNativeType(); + } $parameter = $lastParameter; } } @@ -3822,7 +3831,7 @@ private function processArgs( } if ( $isBuiltin - || ($parameterType === null || !$parameterType->isNull()->no()) + || ($parameterNativeType === null || !$parameterNativeType->isNull()->no()) ) { $scope = $this->lookForSetAllowedUndefinedExpressions($scope, $arg->value); $lookForUnset = true; diff --git a/tests/PHPStan/Rules/Variables/data/pass-by-reference-into-not-nullable.php b/tests/PHPStan/Rules/Variables/data/pass-by-reference-into-not-nullable.php index d0df427cd4..7105479528 100644 --- a/tests/PHPStan/Rules/Variables/data/pass-by-reference-into-not-nullable.php +++ b/tests/PHPStan/Rules/Variables/data/pass-by-reference-into-not-nullable.php @@ -34,3 +34,39 @@ public function test() } } + +class FooPhpDocs +{ + + /** + * @param mixed $test + */ + public function doFooMixedType(&$test) + { + + } + + /** + * @param int $test + */ + public function doFooIntType(&$test) + { + + } + + /** + * @param int|null $test + */ + public function doFooNullableType(&$test) + { + + } + + public function test() + { + $this->doFooMixedType($two); + $this->doFooIntType($three); + $this->doFooNullableType($four); + } + +}