mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
Fixes
This commit is contained in:
parent
b07aba9f47
commit
e628c7b9fc
@ -267,9 +267,13 @@ class ArrayFunctionArgumentsAnalyzer
|
||||
|
||||
if ($was_list) {
|
||||
if ($arg_value_atomic_type instanceof TNonEmptyArray) {
|
||||
$arg_value_atomic_type = Type::getNonEmptyListAtomic($arg_value_atomic_type->type_params[1]);
|
||||
$arg_value_atomic_type = Type::getNonEmptyListAtomic(
|
||||
$arg_value_atomic_type->type_params[1]
|
||||
);
|
||||
} else {
|
||||
$arg_value_atomic_type = Type::getListAtomic($arg_value_atomic_type->type_params[1]);
|
||||
$arg_value_atomic_type = Type::getListAtomic(
|
||||
$arg_value_atomic_type->type_params[1]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,9 +87,15 @@ class UnsetAnalyzer
|
||||
if ($key_value === 0) {
|
||||
$list_key = new Union([new TIntRange(1, null)]);
|
||||
} elseif ($key_value === 1) {
|
||||
$list_key = new Union([new TLiteralInt(0), new TIntRange(2, null)]);
|
||||
$list_key = new Union([
|
||||
new TLiteralInt(0),
|
||||
new TIntRange(2, null)
|
||||
]);
|
||||
} else {
|
||||
$list_key = new Union([new TIntRange(0, $key_value-1), new TIntRange($key_value+1, null)]);
|
||||
$list_key = new Union([
|
||||
new TIntRange(0, $key_value-1),
|
||||
new TIntRange($key_value+1, null)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,6 +107,9 @@ class ArrayMergeReturnTypeProvider implements FunctionReturnTypeProviderInterfac
|
||||
|
||||
$added_inner_values = false;
|
||||
foreach ($unpacked_type_part->properties as $key => $type) {
|
||||
if (!$type->possibly_undefined && !$unpacking_possibly_empty) {
|
||||
$any_nonempty = true;
|
||||
}
|
||||
if (is_string($key)) {
|
||||
$all_int_offsets = false;
|
||||
} elseif (!$is_replace) {
|
||||
@ -152,11 +155,7 @@ class ArrayMergeReturnTypeProvider implements FunctionReturnTypeProviderInterfac
|
||||
$inner_key_types []= new TInt;
|
||||
}
|
||||
|
||||
if ($unpacked_type_part->fallback_params === null) {
|
||||
if (!$unpacking_possibly_empty) {
|
||||
$any_nonempty = true;
|
||||
}
|
||||
} else {
|
||||
if ($unpacked_type_part->fallback_params !== null) {
|
||||
$all_keyed_arrays = false;
|
||||
$inner_value_types = array_merge(
|
||||
$inner_value_types,
|
||||
|
@ -37,6 +37,7 @@ use Psalm\Type\Atomic\TValueOf;
|
||||
|
||||
use function array_merge;
|
||||
use function array_values;
|
||||
use function assert;
|
||||
use function count;
|
||||
use function get_class;
|
||||
use function strtolower;
|
||||
@ -540,10 +541,6 @@ class AtomicTypeComparator
|
||||
foreach ($input_type_part->type_params as $i => $input_param) {
|
||||
$container_param_offset = $i - (2 - count($container_type_part->type_params));
|
||||
|
||||
if ($container_param_offset === -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$container_param = $container_type_part->type_params[$container_param_offset];
|
||||
|
||||
if ($i === 0
|
||||
@ -729,6 +726,9 @@ class AtomicTypeComparator
|
||||
return $input_type_part->getKey() === $container_type_part->getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-assert-if-true TKeyedArray $array
|
||||
*/
|
||||
public static function isLegacyTListLike(Atomic $array): bool
|
||||
{
|
||||
return $array instanceof TKeyedArray
|
||||
@ -739,6 +739,9 @@ class AtomicTypeComparator
|
||||
&& $array->properties[0]->equals($array->fallback_params[1], true, true, false)
|
||||
;
|
||||
}
|
||||
/**
|
||||
* @psalm-assert-if-true TKeyedArray $array
|
||||
*/
|
||||
public static function isLegacyTNonEmptyListLike(Atomic $array): bool
|
||||
{
|
||||
return $array instanceof TKeyedArray
|
||||
@ -763,6 +766,8 @@ class AtomicTypeComparator
|
||||
|| (self::isLegacyTListLike($type2_part)
|
||||
&& self::isLegacyTNonEmptyListLike($type1_part))
|
||||
) {
|
||||
assert($type1_part->fallback_params !== null);
|
||||
assert($type2_part->fallback_params !== null);
|
||||
return UnionTypeComparator::canExpressionTypesBeIdentical(
|
||||
$codebase,
|
||||
$type1_part->fallback_params[1],
|
||||
|
Loading…
Reference in New Issue
Block a user