1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #2958 - prevent overriding final methods

This commit is contained in:
Matthew Brown 2020-03-10 21:26:02 -04:00
parent d1fcbf38ae
commit 1dc26afb27
2 changed files with 27 additions and 0 deletions

View File

@ -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

View File

@ -761,6 +761,17 @@ class ClassTest extends TestCase
}',
'error_message' => 'TypeDoesNotContainType',
],
'cannotOverrideFinalType' => [
'<?php
class P {
public final function f() : void {}
}
class C extends P {
public function f() : void {}
}',
'error_message' => 'MethodSignatureMismatch',
],
];
}
}