diff --git a/src/Psalm/Internal/Analyzer/MethodAnalyzer.php b/src/Psalm/Internal/Analyzer/MethodAnalyzer.php index a28ea4d21..2d210bb3b 100644 --- a/src/Psalm/Internal/Analyzer/MethodAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/MethodAnalyzer.php @@ -586,6 +586,22 @@ class MethodAnalyzer extends FunctionLikeAnalyzer } } + if ($guide_method_storage->final + && $prevent_method_signature_mismatch + && $prevent_abstract_override + ) { + if (IssueBuffer::accepts( + new MethodSignatureMismatch( + 'Method ' . $cased_guide_method_id . ' is declared final and cannot be overridden', + $code_location + ) + )) { + // fall through + } + + return null; + } + if ($prevent_abstract_override && !$guide_method_storage->abstract && $implementer_method_storage->abstract diff --git a/tests/ClassTest.php b/tests/ClassTest.php index 36f7447a3..7777c1968 100644 --- a/tests/ClassTest.php +++ b/tests/ClassTest.php @@ -761,6 +761,17 @@ class ClassTest extends TestCase }', 'error_message' => 'TypeDoesNotContainType', ], + 'cannotOverrideFinalType' => [ + ' 'MethodSignatureMismatch', + ], ]; } }