1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Forbid rejecting named arguments when parent allows them (#5627)

Fixes vimeo/psalm#5622
This commit is contained in:
Bruce Weirdan 2021-04-15 13:55:13 +03:00 committed by GitHub
parent 93e9054f98
commit 93946d0827
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -42,6 +42,7 @@ use function array_search;
use function array_keys;
use function end;
use Psalm\Internal\DataFlow\DataFlowNode;
use Psalm\Issue\MethodSignatureMismatch;
use Psalm\Storage\FunctionStorage;
/**
@ -359,6 +360,19 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
);
}
if ($storage instanceof MethodStorage && $storage->location && !$storage->allow_named_arg_calls) {
foreach ($overridden_method_ids as $overridden_method_id) {
$overridden_storage = $codebase->methods->getStorage($overridden_method_id);
if ($overridden_storage->allow_named_arg_calls) {
IssueBuffer::accepts(new MethodSignatureMismatch(
'Method ' . (string) $method_id . ' should accept named arguments '
. ' as ' . (string) $overridden_method_id . ' does',
$storage->location
));
}
}
}
if (ReturnTypeAnalyzer::checkReturnType(
$this->function,
$project_analyzer,

View File

@ -1546,6 +1546,18 @@ class MethodSignatureTest extends TestCase
}',
'error_message' => 'InvalidReturnType',
],
'disableNamedArgumentsInDescendant' => [
'<?php
interface Foo {
public function bar(string ...$_args): void;
}
final class Baz implements Foo {
/** @no-named-arguments */
public function bar(string ...$_args): void {}
}
',
'error_message' => 'MethodSignatureMismatch',
],
];
}
}