diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index c6a83edc66..89187d27ac 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -408,7 +408,7 @@ private function processStmtNode( foreach ($stmt->attrGroups as $attrGroup) { foreach ($attrGroup->attrs as $attr) { foreach ($attr->args as $arg) { - $nodeCallback($arg->value, $scope); + $this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep()); } } } @@ -469,7 +469,7 @@ private function processStmtNode( foreach ($stmt->attrGroups as $attrGroup) { foreach ($attrGroup->attrs as $attr) { foreach ($attr->args as $arg) { - $nodeCallback($arg->value, $scope); + $this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep()); } } } @@ -644,7 +644,7 @@ private function processStmtNode( foreach ($stmt->attrGroups as $attrGroup) { foreach ($attrGroup->attrs as $attr) { foreach ($attr->args as $arg) { - $nodeCallback($arg->value, $classScope); + $this->processExprNode($arg->value, $classScope, $nodeCallback, ExpressionContext::createDeep()); } } } @@ -660,7 +660,7 @@ private function processStmtNode( foreach ($stmt->attrGroups as $attrGroup) { foreach ($attrGroup->attrs as $attr) { foreach ($attr->args as $arg) { - $nodeCallback($arg->value, $scope); + $this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep()); } } } @@ -1378,7 +1378,7 @@ private function processStmtNode( foreach ($stmt->attrGroups as $attrGroup) { foreach ($attrGroup->attrs as $attr) { foreach ($attr->args as $arg) { - $nodeCallback($arg->value, $scope); + $this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep()); } } } @@ -3068,7 +3068,7 @@ private function processParamNode( foreach ($param->attrGroups as $attrGroup) { foreach ($attrGroup->attrs as $attr) { foreach ($attr->args as $arg) { - $nodeCallback($arg->value, $scope); + $this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep()); } } } diff --git a/tests/PHPStan/Rules/DeadCode/UnusedPrivateConstantRuleTest.php b/tests/PHPStan/Rules/DeadCode/UnusedPrivateConstantRuleTest.php index a6e12e7cab..305c37cf13 100644 --- a/tests/PHPStan/Rules/DeadCode/UnusedPrivateConstantRuleTest.php +++ b/tests/PHPStan/Rules/DeadCode/UnusedPrivateConstantRuleTest.php @@ -46,4 +46,13 @@ public function testRule(): void ]); } + public function testBug5651(): void + { + if (PHP_VERSION_ID < 80000 && !self::$useStaticReflectionProvider) { + $this->markTestSkipped('Test requires PHP 8.0.'); + } + + $this->analyse([__DIR__ . '/data/bug-5651.php'], []); + } + } diff --git a/tests/PHPStan/Rules/DeadCode/data/bug-5651.php b/tests/PHPStan/Rules/DeadCode/data/bug-5651.php new file mode 100644 index 0000000000..88068fd018 --- /dev/null +++ b/tests/PHPStan/Rules/DeadCode/data/bug-5651.php @@ -0,0 +1,30 @@ +values = $values; + } +} + +class HelloWorld +{ + private const BAR = 'bar'; + + #[MyAttribute(['foo' => self::BAR])] + public function sayHello(): void + { + + } +}