mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Forbid rejecting named arguments when parent allows them (#5627)
Fixes vimeo/psalm#5622
This commit is contained in:
parent
93e9054f98
commit
93946d0827
@ -42,6 +42,7 @@ use function array_search;
|
|||||||
use function array_keys;
|
use function array_keys;
|
||||||
use function end;
|
use function end;
|
||||||
use Psalm\Internal\DataFlow\DataFlowNode;
|
use Psalm\Internal\DataFlow\DataFlowNode;
|
||||||
|
use Psalm\Issue\MethodSignatureMismatch;
|
||||||
use Psalm\Storage\FunctionStorage;
|
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(
|
if (ReturnTypeAnalyzer::checkReturnType(
|
||||||
$this->function,
|
$this->function,
|
||||||
$project_analyzer,
|
$project_analyzer,
|
||||||
|
@ -1546,6 +1546,18 @@ class MethodSignatureTest extends TestCase
|
|||||||
}',
|
}',
|
||||||
'error_message' => 'InvalidReturnType',
|
'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',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user