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

Expand documentation method return type to ensure we’re giving a fair shot

This commit is contained in:
Matt Brown 2021-03-18 11:06:54 -04:00
parent 45694d37d4
commit 04f3e29f94
2 changed files with 66 additions and 2 deletions

View File

@ -764,15 +764,29 @@ class Methods
return clone $candidate_type;
}
$overridden_class_storage =
$this->classlike_storage_provider->get($overridden_method_id->fq_class_name);
$overridden_storage_return_type = \Psalm\Internal\Type\TypeExpander::expandUnion(
$source_analyzer->getCodebase(),
clone $overridden_storage->return_type,
$overridden_method_id->fq_class_name,
$appearing_fq_class_name,
$overridden_class_storage->parent_class,
true,
false,
$storage->final
);
$old_contained_by_new = UnionTypeComparator::isContainedBy(
$source_analyzer->getCodebase(),
$candidate_type,
$overridden_storage->return_type
$overridden_storage_return_type
);
$new_contained_by_old = UnionTypeComparator::isContainedBy(
$source_analyzer->getCodebase(),
$overridden_storage->return_type,
$overridden_storage_return_type,
$candidate_type
);

View File

@ -4350,6 +4350,56 @@ class ClassTemplateExtendsTest extends TestCase
$foo = new ObjectStorage();'
],
'liskovTerminatedByFinalClass' => [
'<?php
final class CustomEnum extends Enum
{
public static function all() : CustomEnumSet
{
return new CustomEnumSet();
}
}
/**
* @template T of Enum
*/
class EnumSet
{
private $type;
/**
* @param class-string<T> $type
*/
public function __construct(string $type)
{
$this->type = $type;
}
}
abstract class Enum {
/**
* @return EnumSet<static>
*/
public static function all() : EnumSet
{
return new EnumSet(static::class);
}
}
/**
* @extends EnumSet<CustomEnum>
*/
final class CustomEnumSet extends EnumSet {
public function __construct()
{
parent::__construct(CustomEnum::class);
}
}',
[],
[],
'7.4'
],
];
}