mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Invalidate child methods when signature changes
This commit is contained in:
parent
9d35e3c251
commit
badf0855ce
@ -50,11 +50,13 @@ class MethodComparator
|
||||
bool $prevent_abstract_override = true,
|
||||
bool $prevent_method_signature_mismatch = true
|
||||
): ?bool {
|
||||
$implementer_method_id = new MethodIdentifier(
|
||||
$implementer_classlike_storage->name,
|
||||
strtolower($guide_method_storage->cased_name ?: '')
|
||||
);
|
||||
|
||||
$implementer_declaring_method_id = $codebase->methods->getDeclaringMethodId(
|
||||
new MethodIdentifier(
|
||||
$implementer_classlike_storage->name,
|
||||
strtolower($guide_method_storage->cased_name ?: '')
|
||||
)
|
||||
$implementer_method_id
|
||||
);
|
||||
|
||||
$cased_implementer_method_id = $implementer_classlike_storage->name . '::'
|
||||
@ -62,6 +64,11 @@ class MethodComparator
|
||||
|
||||
$cased_guide_method_id = $guide_classlike_storage->name . '::' . $guide_method_storage->cased_name;
|
||||
|
||||
$codebase->methods->file_reference_provider->addMethodReferenceToClassMember(
|
||||
strtolower((string)($implementer_declaring_method_id ?: $implementer_method_id)),
|
||||
strtolower($guide_classlike_storage->name . '::' . $guide_method_storage->cased_name)
|
||||
);
|
||||
|
||||
self::checkForObviousMethodMismatches(
|
||||
$guide_classlike_storage,
|
||||
$implementer_classlike_storage,
|
||||
|
@ -907,6 +907,43 @@ class ErrorAfterUpdateTest extends \Psalm\Tests\TestCase
|
||||
],
|
||||
'error_message' => 'PropertyNotSetInConstructor',
|
||||
],
|
||||
'invalidateChildMethodWhenSignatureChanges' => [
|
||||
'file_stages' => [
|
||||
[
|
||||
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
||||
namespace Foo;
|
||||
|
||||
class A {
|
||||
public function foo(string $s) : void {
|
||||
echo $s;
|
||||
}
|
||||
}
|
||||
|
||||
class AChild extends A {
|
||||
public function foo(string $s) : void {
|
||||
echo $s;
|
||||
}
|
||||
}',
|
||||
],
|
||||
[
|
||||
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
|
||||
namespace Foo;
|
||||
|
||||
class A {
|
||||
public function foo(string $s = "") : void {
|
||||
echo $s;
|
||||
}
|
||||
}
|
||||
|
||||
class AChild extends A {
|
||||
public function foo(string $s) : void {
|
||||
echo $s;
|
||||
}
|
||||
}',
|
||||
],
|
||||
],
|
||||
'error_message' => 'MethodSignatureMismatch',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user