diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php index c8edcf6723e..dd97adf9b80 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php @@ -1338,10 +1338,8 @@ private function visitClassConstDeclaration( ); $type_location = null; - $suppressed_issues = []; - if ($var_comment !== null && $var_comment->type !== null) { + 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 @@ -1357,6 +1355,7 @@ private function visitClassConstDeclaration( } else { $const_type = $inferred_type; } + $suppressed_issues = $var_comment ? $var_comment->suppressed_issues : []; $attributes = []; foreach ($stmt->attrGroups as $attr_group) { @@ -1420,8 +1419,8 @@ private function visitClassConstDeclaration( $description, ); - 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'