diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/ClassConstAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/ClassConstAnalyzer.php index 6926f6ed0..5e8db7bae 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/ClassConstAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/ClassConstAnalyzer.php @@ -780,7 +780,7 @@ class ClassConstAnalyzer } // Check overridden final - if ($parent_const_storage->final) { + if ($parent_const_storage->final && $parent_const_storage !== $const_storage) { IssueBuffer::maybeAdd( new OverriddenFinalConstant( "{$const_name} cannot be overridden because it is marked as final in " diff --git a/tests/ConstantTest.php b/tests/ConstantTest.php index dccd9c85c..c7152b432 100644 --- a/tests/ConstantTest.php +++ b/tests/ConstantTest.php @@ -1482,6 +1482,44 @@ class ConstantTest extends TestCase } ', ], + 'finalConst' => [ + 'code' => ' [ + '$a===' => "'baz'" + ], + 'ignored_issues' => [], + 'php_version' => '8.1' + ], + 'finalConstInterface' => [ + 'code' => ' [ + '$a===' => "'baz'" + ], + 'ignored_issues' => [], + 'php_version' => '8.1' + ], ]; }