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:
parent
61f02d8889
commit
44f9440664
@ -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);
|
||||
|
@ -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 */
|
||||
|
@ -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',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user