1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-03 18:17:55 +01:00
This commit is contained in:
Daniil Gentili 2022-11-26 15:11:43 +01:00
parent 668afa9caf
commit 956fa4458e

View File

@ -562,6 +562,7 @@ class SimpleAssertionReconciler extends Reconciler
} }
/** /**
* @param NonEmptyCountable|HasAtLeastCount $assertion
* @param string[] $suppressed_issues * @param string[] $suppressed_issues
*/ */
private static function reconcileNonEmptyCountable( private static function reconcileNonEmptyCountable(
@ -599,20 +600,6 @@ class SimpleAssertionReconciler extends Reconciler
$redundant = false; $redundant = false;
} }
} elseif ($array_atomic_type instanceof TList) {
if (!$array_atomic_type instanceof TNonEmptyList
|| ($assertion instanceof HasAtLeastCount
&& $array_atomic_type->count < $assertion->count)
) {
$non_empty_list = Type::getNonEmptyListAtomic(
$array_atomic_type->type_param,
null,
$assertion instanceof HasAtLeastCount ? $assertion->count : null
);
$redundant = false;
$existing_var_type->addType($non_empty_list);
}
} elseif ($array_atomic_type instanceof TKeyedArray) { } elseif ($array_atomic_type instanceof TKeyedArray) {
$prop_max_count = count($array_atomic_type->properties); $prop_max_count = count($array_atomic_type->properties);
$prop_min_count = 0; $prop_min_count = 0;
@ -659,17 +646,16 @@ class SimpleAssertionReconciler extends Reconciler
} else { } else {
$redundant = false; $redundant = false;
} }
} elseif ($array_atomic_type->is_list } elseif ($array_atomic_type->is_list) {
&& $prop_min_count === $prop_max_count
) {
if ($assertion->count <= $prop_min_count) { if ($assertion->count <= $prop_min_count) {
$redundant = true; $redundant = true;
} else { } else {
$redundant = false; $redundant = false;
$properties = $array_atomic_type->properties; $properties = $array_atomic_type->properties;
for ($i = $prop_max_count; $i < $assertion->count; $i++) { for ($i = $prop_max_count; $i < $assertion->count; $i++) {
$properties[$i] $properties[$i] = $properties[$i]
= $array_atomic_type->fallback_params[1]; ? $properties[$i]->setPossiblyUndefined(false)
: $array_atomic_type->fallback_params[1];
} }
$array_atomic_type = $array_atomic_type->setProperties($properties); $array_atomic_type = $array_atomic_type->setProperties($properties);
$existing_var_type->removeType('array'); $existing_var_type->removeType('array');