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:
parent
d1fcbf38ae
commit
1dc26afb27
@ -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
|
||||
|
@ -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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user