diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php index c8edcf6723e..0b591f19467 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php @@ -1338,10 +1338,9 @@ private function visitClassConstDeclaration( ); $type_location = null; - $suppressed_issues = []; - if ($var_comment !== null && $var_comment->type !== null) { + $suppressed_issues = $var_comment ? $var_comment->suppressed_issues : []; + if ($var_comment && $var_comment->type !== null) { $const_type = $var_comment->type; - $suppressed_issues = $var_comment->suppressed_issues; if ($var_comment->type_start !== null && $var_comment->type_end !== null @@ -1421,7 +1420,9 @@ private function visitClassConstDeclaration( ); + if ($this->codebase->analysis_php_version_id >= 8_03_00 + && !$storage->final && $stmt->type === null ) { IssueBuffer::maybeAdd( diff --git a/tests/MissingClassConstTypeTest.php b/tests/MissingClassConstTypeTest.php index de413050fdb..adabb5ab269 100644 --- a/tests/MissingClassConstTypeTest.php +++ b/tests/MissingClassConstTypeTest.php @@ -27,6 +27,29 @@ class A { 'ignored_issues' => [], 'php_version' => '8.3', ], + 'no type; >= PHP 8.3; but class is final' => [ + 'code' => <<<'PHP' + [], + 'ignored_issues' => [], + 'php_version' => '8.3', + ], + 'no type; >= PHP 8.3; but psalm-suppressed' => [ + 'code' => <<<'PHP' + [], + 'ignored_issues' => [], + 'php_version' => '8.3', + ], 'no type; < PHP 8.3' => [ 'code' => <<<'PHP'