diff --git a/src/Analyser/ImpurePoint.php b/src/Analyser/ImpurePoint.php index e5f89255ed..59fccfac36 100644 --- a/src/Analyser/ImpurePoint.php +++ b/src/Analyser/ImpurePoint.php @@ -6,7 +6,7 @@ use PHPStan\Node\VirtualNode; /** - * @phpstan-type ImpurePointIdentifier = 'echo'|'die'|'exit'|'propertyAssign'|'methodCall'|'new'|'functionCall'|'include'|'require'|'print'|'eval'|'superglobal'|'yield'|'yieldFrom'|'static'|'global'|'betweenPhpTags' + * @phpstan-type ImpurePointIdentifier = 'echo'|'die'|'exit'|'propertyAssign'|'propertyUnset'|'methodCall'|'new'|'functionCall'|'include'|'require'|'print'|'eval'|'superglobal'|'yield'|'yieldFrom'|'static'|'global'|'betweenPhpTags' * @api */ class ImpurePoint diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 6e253a71db..9abf5a6520 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -1687,6 +1687,15 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void { static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, [], []), false, )->getScope(); + } elseif ($var instanceof PropertyFetch) { + $scope = $scope->invalidateExpression($var); + $impurePoints[] = new ImpurePoint( + $scope, + $var, + 'propertyUnset', + 'property unset', + true, + ); } else { $scope = $scope->invalidateExpression($var); } diff --git a/tests/PHPStan/Rules/DeadCode/BetterNoopRuleTest.php b/tests/PHPStan/Rules/DeadCode/BetterNoopRuleTest.php index dd472321ea..6a0780ad36 100644 --- a/tests/PHPStan/Rules/DeadCode/BetterNoopRuleTest.php +++ b/tests/PHPStan/Rules/DeadCode/BetterNoopRuleTest.php @@ -143,4 +143,9 @@ public function testRuleImpurePoints(): void ]); } + public function testBug11001(): void + { + $this->analyse([__DIR__ . '/data/bug-11001.php'], []); + } + } diff --git a/tests/PHPStan/Rules/DeadCode/data/bug-11001.php b/tests/PHPStan/Rules/DeadCode/data/bug-11001.php new file mode 100644 index 0000000000..a5b8182222 --- /dev/null +++ b/tests/PHPStan/Rules/DeadCode/data/bug-11001.php @@ -0,0 +1,23 @@ +foo); + })(); + } + +}