mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #566 - check for abstract methods inheriting from non-abstract ones
This commit is contained in:
parent
5cd8b3cccd
commit
ef35cfc6fe
@ -782,7 +782,10 @@ class ClassChecker extends ClassLikeChecker
|
||||
$global_context ? clone $global_context : null
|
||||
);
|
||||
|
||||
if ($stmt->name !== '__construct' && $config->reportIssueInFile('InvalidReturnType', $source->getFilePath())) {
|
||||
if ($stmt->name !== '__construct'
|
||||
&& $config->reportIssueInFile('InvalidReturnType', $source->getFilePath())
|
||||
&& $stmt->stmts !== null
|
||||
) {
|
||||
$return_type_location = null;
|
||||
$secondary_return_type_location = null;
|
||||
|
||||
|
@ -392,6 +392,23 @@ class MethodChecker extends FunctionLikeChecker
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$guide_method_storage->abstract
|
||||
&& $implementer_method_storage->abstract
|
||||
&& !$implementer_classlike_storage->abstract
|
||||
) {
|
||||
if (IssueBuffer::accepts(
|
||||
new MethodSignatureMismatch(
|
||||
'Method ' . $cased_implementer_method_id . ' cannot be abstract when inherited method '
|
||||
. $cased_guide_method_id . ' is non-abstract',
|
||||
$code_location
|
||||
)
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($guide_method_storage->signature_return_type) {
|
||||
$guide_signature_return_type = ExpressionChecker::fleshOutType(
|
||||
$project_checker,
|
||||
|
@ -27,6 +27,8 @@ class FileStorageCacheProvider
|
||||
$dependent_files = [
|
||||
$storage_dir . 'FileStorage.php',
|
||||
$storage_dir . 'FunctionLikeStorage.php',
|
||||
$storage_dir . 'ClassLikeStorage.php',
|
||||
$storage_dir . 'MethodStorage.php',
|
||||
];
|
||||
|
||||
foreach ($dependent_files as $dependent_file_path) {
|
||||
|
@ -67,11 +67,6 @@ class FunctionLikeStorage
|
||||
*/
|
||||
public $returns_by_ref = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $abstract = false;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -20,6 +20,11 @@ class MethodStorage extends FunctionLikeStorage
|
||||
*/
|
||||
public $final;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $abstract;
|
||||
|
||||
/**
|
||||
* @var array<int, CodeLocation>
|
||||
*/
|
||||
|
@ -102,6 +102,9 @@ $vendor_dir = getVendorDir($current_dir);
|
||||
|
||||
$first_autoloader = requireAutoloaders($current_dir, isset($options['r']), $vendor_dir);
|
||||
|
||||
// If XDebug is enabled, restart without it
|
||||
(new \Composer\XdebugHandler\XdebugHandler('PSALTER'))->check();
|
||||
|
||||
$paths_to_check = getPathsToCheck(isset($options['f']) ? $options['f'] : null);
|
||||
|
||||
if ($paths_to_check && count($paths_to_check) > 1) {
|
||||
|
@ -430,6 +430,17 @@ class MethodSignatureTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'MethodSignatureMismatch',
|
||||
],
|
||||
'abstractExtendsNonAbstractWithMethod' => [
|
||||
'<?php
|
||||
class A {
|
||||
public function foo() : void {}
|
||||
}
|
||||
|
||||
abstract class B extends A {
|
||||
abstract public function foo() : void;
|
||||
}',
|
||||
'error_message' => 'MethodSignatureMismatch',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user