From f158d5bf32135d90a31f14993a3d2196cb456b3b Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Tue, 12 Nov 2024 17:35:18 +0100 Subject: [PATCH] Do not report nonexistent variable passed to by-ref parameter with checkImplicitMixed --- src/Rules/FunctionCallParametersCheck.php | 6 +++++- .../Methods/CallStaticMethodsRuleTest.php | 8 +++++++ .../PHPStan/Rules/Methods/data/bug-12015.php | 21 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/PHPStan/Rules/Methods/data/bug-12015.php diff --git a/src/Rules/FunctionCallParametersCheck.php b/src/Rules/FunctionCallParametersCheck.php index 40fb657bcc..623b593f5f 100644 --- a/src/Rules/FunctionCallParametersCheck.php +++ b/src/Rules/FunctionCallParametersCheck.php @@ -313,7 +313,11 @@ public function check( if ( !$parameter->passedByReference()->createsNewVariable() - || (!$isBuiltin && $this->checkUnresolvableParameterTypes) // bleeding edge only + || ( + !$isBuiltin + && $this->checkUnresolvableParameterTypes // bleeding edge only + && !$argumentValueType instanceof ErrorType + ) ) { $accepts = $this->ruleLevelHelper->acceptsWithReason($parameterType, $argumentValueType, $scope->isDeclareStrictTypes()); diff --git a/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php index 1246699ff8..fbb5e41439 100644 --- a/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php @@ -849,4 +849,12 @@ public function testBug10872(): void $this->analyse([__DIR__ . '/data/bug-10872.php'], []); } + public function testBug12015(): void + { + $this->checkThisOnly = false; + $this->checkExplicitMixed = true; + $this->checkImplicitMixed = true; + $this->analyse([__DIR__ . '/data/bug-12015.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Methods/data/bug-12015.php b/tests/PHPStan/Rules/Methods/data/bug-12015.php new file mode 100644 index 0000000000..c2a5618cd8 --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/bug-12015.php @@ -0,0 +1,21 @@ +