diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 37094ae9de..0a80b7639b 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -1486,6 +1486,13 @@ private function processStmtNode( $scope->getNativeType($const->value), ); } + } elseif ($stmt instanceof Node\Stmt\EnumCase) { + $hasYield = false; + $throwPoints = []; + $this->processAttributeGroups($stmt->attrGroups, $scope, $nodeCallback); + if ($stmt->expr !== null) { + $this->processExprNode($stmt->expr, $scope, $nodeCallback, ExpressionContext::createDeep()); + } } elseif ($stmt instanceof Node\Stmt\Nop) { $hasYield = false; $throwPoints = $overridingThrowPoints ?? []; diff --git a/tests/PHPStan/Node/AttributeArgRuleTest.php b/tests/PHPStan/Node/AttributeArgRuleTest.php index 29773859d8..fb4c1d99e9 100644 --- a/tests/PHPStan/Node/AttributeArgRuleTest.php +++ b/tests/PHPStan/Node/AttributeArgRuleTest.php @@ -5,6 +5,7 @@ use PhpParser\Node; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -42,4 +43,18 @@ public function testRule(string $file, string $expectedError, array $lines): voi $this->analyse([$file], $errors); } + public function testEnumCaseAttribute(): void + { + if (PHP_VERSION_ID < 80100) { + $this->markTestSkipped('Test requires PHP 8.1.'); + } + + $this->analyse([__DIR__ . '/data/enum-case-attribute.php'], [ + [ + AttributeArgRule::ERROR_MESSAGE, + 10, + ], + ]); + } + } diff --git a/tests/PHPStan/Node/data/enum-case-attribute.php b/tests/PHPStan/Node/data/enum-case-attribute.php new file mode 100644 index 0000000000..93e87ef1f6 --- /dev/null +++ b/tests/PHPStan/Node/data/enum-case-attribute.php @@ -0,0 +1,13 @@ += 8.1 + +namespace EnumCaseAttributeCheck; + +use NodeCallbackCalled\UniversalAttribute; + +enum Foo +{ + + #[UniversalAttribute(1)] + case TEST; + +} diff --git a/tests/PHPStan/Rules/DeadCode/UnusedPrivateConstantRuleTest.php b/tests/PHPStan/Rules/DeadCode/UnusedPrivateConstantRuleTest.php index 08d6825213..73076bf285 100644 --- a/tests/PHPStan/Rules/DeadCode/UnusedPrivateConstantRuleTest.php +++ b/tests/PHPStan/Rules/DeadCode/UnusedPrivateConstantRuleTest.php @@ -83,4 +83,13 @@ public function testBug8204(): void $this->analyse([__DIR__ . '/data/bug-8204.php'], []); } + public function testBug9005(): void + { + if (PHP_VERSION_ID < 80100) { + $this->markTestSkipped('Test requires PHP 8.1.'); + } + + $this->analyse([__DIR__ . '/data/bug-9005.php'], []); + } + } diff --git a/tests/PHPStan/Rules/DeadCode/data/bug-9005.php b/tests/PHPStan/Rules/DeadCode/data/bug-9005.php new file mode 100644 index 0000000000..ebe4725ab3 --- /dev/null +++ b/tests/PHPStan/Rules/DeadCode/data/bug-9005.php @@ -0,0 +1,12 @@ += 8.1 + +namespace Bug9005; + +enum Test: string +{ + private const PREFIX = 'my-stuff-'; + + case TESTING = self::PREFIX . 'test'; + + case TESTING2 = self::PREFIX . 'test2'; +}