mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix inference for empty arrays
This commit is contained in:
parent
eb71506a59
commit
881dbf86e1
@ -33,11 +33,20 @@ class ArrayTypeComparator
|
||||
) : bool {
|
||||
$all_types_contain = true;
|
||||
|
||||
$is_empty_array = $input_type_part->getId() === 'array<empty, empty>';
|
||||
$is_empty_array = $input_type_part->equals(
|
||||
new Type\Atomic\TArray([
|
||||
new Type\Union([new Type\Atomic\TEmpty()]),
|
||||
new Type\Union([new Type\Atomic\TEmpty()])
|
||||
]),
|
||||
false
|
||||
);
|
||||
|
||||
if ($is_empty_array
|
||||
&& ($container_type_part instanceof Type\Atomic\TArray
|
||||
|| $container_type_part instanceof Type\Atomic\TKeyedArray)
|
||||
&& !$container_type_part instanceof Type\Atomic\TNonEmptyArray
|
||||
&& (($container_type_part instanceof Type\Atomic\TArray
|
||||
&& !$container_type_part instanceof Type\Atomic\TNonEmptyArray)
|
||||
|| ($container_type_part instanceof Type\Atomic\TKeyedArray
|
||||
&& !$container_type_part->isNonEmpty())
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
@ -294,6 +294,17 @@ class TKeyedArray extends \Psalm\Type\Atomic
|
||||
return $array_type;
|
||||
}
|
||||
|
||||
public function isNonEmpty(): bool
|
||||
{
|
||||
foreach ($this->properties as $key => $property) {
|
||||
if (!$property->possibly_undefined) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
foreach ($this->properties as &$property) {
|
||||
|
Loading…
Reference in New Issue
Block a user