mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Allow object-like with all optional vars to be compared to empty array
This commit is contained in:
parent
452fd2e7c9
commit
bc0c4322d5
@ -347,14 +347,18 @@ class TypeChecker
|
||||
&& ($container_type_part instanceof TArray || $container_type_part instanceof ObjectLike)
|
||||
) {
|
||||
if ($container_type_part instanceof ObjectLike) {
|
||||
$generic_container_type_part = $container_type_part->getGenericArrayType();
|
||||
|
||||
if (!$input_type_part instanceof ObjectLike
|
||||
&& !$input_type_part->type_params[0]->isMixed()
|
||||
&& !($input_type_part->type_params[1]->isEmpty()
|
||||
&& $generic_container_type_part->type_params[1]->possibly_undefined)
|
||||
) {
|
||||
$all_types_contain = false;
|
||||
$type_coerced = true;
|
||||
}
|
||||
|
||||
$container_type_part = $container_type_part->getGenericArrayType();
|
||||
$container_type_part = $generic_container_type_part;
|
||||
}
|
||||
|
||||
if ($input_type_part instanceof ObjectLike) {
|
||||
|
@ -659,7 +659,7 @@ abstract class Type
|
||||
$combined_type->failed_reconciliation = true;
|
||||
}
|
||||
|
||||
if ($type_1->possibly_undefined || $type_2->possibly_undefined) {
|
||||
if ($type_1->possibly_undefined && $type_2->possibly_undefined) {
|
||||
$combined_type->possibly_undefined = true;
|
||||
}
|
||||
|
||||
|
@ -185,8 +185,6 @@ class ObjectLike extends \Psalm\Type\Atomic
|
||||
throw new \UnexpectedValueException('$value_type should not be null here');
|
||||
}
|
||||
|
||||
$value_type->possibly_undefined = false;
|
||||
|
||||
return new TArray([Type::combineTypes($key_types), $value_type]);
|
||||
}
|
||||
|
||||
|
@ -731,6 +731,11 @@ class AnnotationTest extends TestCase
|
||||
'annotations' => [],
|
||||
'error_levels' => ['LessSpecificReturnStatement', 'MoreSpecificReturnType'],
|
||||
],
|
||||
'allowOptionalParamsToBeEmptyArray' => [
|
||||
'<?php
|
||||
/** @param array{b?: int, c?: string} $a */
|
||||
function foo(array $a = []) : void {}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user