diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/ClassConstAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/ClassConstAnalyzer.php index 6926f6ed0b1..5e8db7bae83 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/ClassConstAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/ClassConstAnalyzer.php @@ -780,7 +780,7 @@ public static function analyze( } // 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 dccd9c85cc4..c7152b43287 100644 --- a/tests/ConstantTest.php +++ b/tests/ConstantTest.php @@ -1482,6 +1482,44 @@ class Foo { } ', ], + 'finalConst' => [ + 'code' => ' [ + '$a===' => "'baz'" + ], + 'ignored_issues' => [], + 'php_version' => '8.1' + ], + 'finalConstInterface' => [ + 'code' => ' [ + '$a===' => "'baz'" + ], + 'ignored_issues' => [], + 'php_version' => '8.1' + ], ]; }