From da21229cab76cb785643edef2be3bf2cb38492ec Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 5 Nov 2022 19:15:46 +0100 Subject: [PATCH] Fix #8664 --- .../Expression/ClassConstAnalyzer.php | 2 +- tests/ConstantTest.php | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) 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' + ], ]; }