1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Only inherit docblock param type if they type was not expanded

fixes this issue: https://psalm.dev/r/edaea88e00
This commit is contained in:
robchett 2023-11-09 11:32:58 +00:00
parent 61f02d8889
commit 44f9440664
3 changed files with 33 additions and 1 deletions

View File

@ -311,7 +311,6 @@ class CallAnalyzer
$declaring_method_id = $class_storage->declaring_method_ids[$method_name];
$declaring_fq_class_name = $declaring_method_id->fq_class_name;
$declaring_method_name = $declaring_method_id->method_name;
if ($declaring_fq_class_name !== $fq_class_name) {
$declaring_class_storage = $codebase->classlike_storage_provider->get($declaring_fq_class_name);

View File

@ -459,6 +459,13 @@ final class Methods
foreach ($params as $i => $param) {
if (isset($overridden_storage->params[$i]->type)
&& $overridden_storage->params[$i]->has_docblock_type
&& (
! $param->type
|| $param->type->equals(
$overridden_storage->params[$i]->signature_type
?? $overridden_storage->params[$i]->type,
)
)
) {
$params[$i] = clone $param;
/** @var Union $params[$i]->type */

View File

@ -149,6 +149,32 @@ class DocblockInheritanceTest extends TestCase
return $f->map();
}',
],
'inheritCorrectParamOnTypeChange' => [
'code' => '<?php
class A
{
/** @param array<int, int>|int $className */
public function a(array|int $className): int
{
return 0;
}
}
class B extends A
{
public function a(array|int|bool $className): int
{
return 0;
}
}
print_r((new A)->a(1));
print_r((new B)->a(true));
',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.0',
],
];
}