From 50f2a08e04d8c7a2833c66929fab857579f855ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Mirtes?= Date: Sun, 8 Jan 2023 18:26:27 +0100 Subject: [PATCH] Revert Passing a variable by reference to a function and method has side effects This reverts commit 1070788017dcd03527882b454c671fe97d6c91b8. --- .../AnnotationMethodReflection.php | 8 -------- .../Native/NativeFunctionReflection.php | 7 ------- .../Native/NativeMethodReflection.php | 7 ------- .../PhpFunctionFromParserNodeReflection.php | 7 ------- src/Reflection/Php/PhpFunctionReflection.php | 7 ------- src/Reflection/Php/PhpMethodReflection.php | 7 ------- .../Analyser/NodeScopeResolverTest.php | 1 - tests/PHPStan/Analyser/data/bug-8084.php | 20 ------------------- .../Rules/Variables/NullCoalesceRuleTest.php | 8 -------- .../PHPStan/Rules/Variables/data/bug-8084.php | 19 ------------------ 10 files changed, 91 deletions(-) delete mode 100644 tests/PHPStan/Analyser/data/bug-8084.php delete mode 100644 tests/PHPStan/Rules/Variables/data/bug-8084.php diff --git a/src/Reflection/Annotations/AnnotationMethodReflection.php b/src/Reflection/Annotations/AnnotationMethodReflection.php index 02d0616b43..4ca52b8cd8 100644 --- a/src/Reflection/Annotations/AnnotationMethodReflection.php +++ b/src/Reflection/Annotations/AnnotationMethodReflection.php @@ -113,14 +113,6 @@ public function hasSideEffects(): TrinaryLogic return TrinaryLogic::createYes(); } - foreach ($this->getVariants() as $variant) { - foreach ($variant->getParameters() as $parameter) { - if ($parameter->passedByReference()->yes()) { - return TrinaryLogic::createYes(); - } - } - } - return TrinaryLogic::createMaybe(); } diff --git a/src/Reflection/Native/NativeFunctionReflection.php b/src/Reflection/Native/NativeFunctionReflection.php index b650dc5469..b2481b7411 100644 --- a/src/Reflection/Native/NativeFunctionReflection.php +++ b/src/Reflection/Native/NativeFunctionReflection.php @@ -81,13 +81,6 @@ public function hasSideEffects(): TrinaryLogic if ($this->isVoid()) { return TrinaryLogic::createYes(); } - foreach ($this->variants as $variant) { - foreach ($variant->getParameters() as $parameter) { - if ($parameter->passedByReference()->yes()) { - return TrinaryLogic::createYes(); - } - } - } return $this->hasSideEffects; } diff --git a/src/Reflection/Native/NativeMethodReflection.php b/src/Reflection/Native/NativeMethodReflection.php index 1a6c90dbd3..f61c89c41a 100644 --- a/src/Reflection/Native/NativeMethodReflection.php +++ b/src/Reflection/Native/NativeMethodReflection.php @@ -136,13 +136,6 @@ public function hasSideEffects(): TrinaryLogic ) { return TrinaryLogic::createYes(); } - foreach ($this->variants as $variant) { - foreach ($variant->getParameters() as $parameter) { - if ($parameter->passedByReference()->yes()) { - return TrinaryLogic::createYes(); - } - } - } return $this->hasSideEffects; } diff --git a/src/Reflection/Php/PhpFunctionFromParserNodeReflection.php b/src/Reflection/Php/PhpFunctionFromParserNodeReflection.php index 9edb2327c6..3b5f8d770d 100644 --- a/src/Reflection/Php/PhpFunctionFromParserNodeReflection.php +++ b/src/Reflection/Php/PhpFunctionFromParserNodeReflection.php @@ -199,13 +199,6 @@ public function hasSideEffects(): TrinaryLogic if ($this->isPure !== null) { return TrinaryLogic::createFromBoolean(!$this->isPure); } - foreach ($this->getVariants() as $variant) { - foreach ($variant->getParameters() as $parameter) { - if ($parameter->passedByReference()->yes()) { - return TrinaryLogic::createYes(); - } - } - } return TrinaryLogic::createMaybe(); } diff --git a/src/Reflection/Php/PhpFunctionReflection.php b/src/Reflection/Php/PhpFunctionReflection.php index 71a2c16cc9..2627fdd927 100644 --- a/src/Reflection/Php/PhpFunctionReflection.php +++ b/src/Reflection/Php/PhpFunctionReflection.php @@ -245,13 +245,6 @@ public function hasSideEffects(): TrinaryLogic if ($this->isPure !== null) { return TrinaryLogic::createFromBoolean(!$this->isPure); } - foreach ($this->getVariants() as $variant) { - foreach ($variant->getParameters() as $parameter) { - if ($parameter->passedByReference()->yes()) { - return TrinaryLogic::createYes(); - } - } - } return TrinaryLogic::createMaybe(); } diff --git a/src/Reflection/Php/PhpMethodReflection.php b/src/Reflection/Php/PhpMethodReflection.php index e4b265d1e6..62d7b1312a 100644 --- a/src/Reflection/Php/PhpMethodReflection.php +++ b/src/Reflection/Php/PhpMethodReflection.php @@ -416,13 +416,6 @@ public function hasSideEffects(): TrinaryLogic if ($this->isPure !== null) { return TrinaryLogic::createFromBoolean(!$this->isPure); } - foreach ($this->getVariants() as $variant) { - foreach ($variant->getParameters() as $parameter) { - if ($parameter->passedByReference()->yes()) { - return TrinaryLogic::createYes(); - } - } - } return TrinaryLogic::createMaybe(); } diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 34798c2deb..3ba511001d 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -1171,7 +1171,6 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8635.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8625.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8621.php'); - yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8084.php'); } /** diff --git a/tests/PHPStan/Analyser/data/bug-8084.php b/tests/PHPStan/Analyser/data/bug-8084.php deleted file mode 100644 index 255c38bdde..0000000000 --- a/tests/PHPStan/Analyser/data/bug-8084.php +++ /dev/null @@ -1,20 +0,0 @@ -analyse([__DIR__ . '/data/bug-7968.php'], []); } - public function testBug8084(): void - { - $this->treatPhpDocTypesAsCertain = true; - $this->strictUnnecessaryNullsafePropertyFetch = true; - - $this->analyse([__DIR__ . '/data/bug-8084.php'], []); - } - } diff --git a/tests/PHPStan/Rules/Variables/data/bug-8084.php b/tests/PHPStan/Rules/Variables/data/bug-8084.php deleted file mode 100644 index 7bd7e8d435..0000000000 --- a/tests/PHPStan/Rules/Variables/data/bug-8084.php +++ /dev/null @@ -1,19 +0,0 @@ -= 8.0 - -namespace Bug8084; - -use Exception; -use function array_shift; -use function PHPStan\Testing\assertType; - -class Bug8084 -{ - /** - * @param array{a?: 0} $arr - * @throws Exception - */ - public function run(array $arr): void - { - assertType('0|null', array_shift($arr) ?? throw new Exception()); - } -}