1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 12:24:49 +01:00

Invalidate child methods when signature changes

This commit is contained in:
Matt Brown 2020-11-01 09:46:21 -05:00 committed by Daniil Gentili
parent 9d35e3c251
commit badf0855ce
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 48 additions and 4 deletions

View File

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

View File

@ -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',
],
];
}
}