Skip to content

Commit

Permalink
Merge pull request #10953 from jack-worman/Fix-GH-10933-And-GH-10951
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed May 5, 2024
2 parents 462c80e + 3708807 commit 7552679
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down
23 changes: 23 additions & 0 deletions tests/MissingClassConstTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ class A {
'ignored_issues' => [],
'php_version' => '8.3',
],
'no type; >= PHP 8.3; but class is final' => [
'code' => <<<'PHP'
<?php
final class A {
public const B = 0;
}
PHP,
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.3',
],
'no type; >= PHP 8.3; but psalm-suppressed' => [
'code' => <<<'PHP'
<?php
class A {
/** @psalm-suppress MissingClassConstType */
public const B = 0;
}
PHP,
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.3',
],
'no type; < PHP 8.3' => [
'code' => <<<'PHP'
<?php
Expand Down

0 comments on commit 7552679

Please sign in to comment.