1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-12 09:19:40 +01:00
This commit is contained in:
Daniil Gentili 2022-12-01 20:30:11 +01:00
parent 03fc544af4
commit e529402e34

View File

@ -1505,18 +1505,8 @@ class ArrayFetchAnalyzer
): void { ): void {
$generic_key_type = $type->getGenericKeyType(); $generic_key_type = $type->getGenericKeyType();
if (!$stmt->dim && $type->fallback_params === null) { if (!$stmt->dim && $type->fallback_params === null && $type->is_list) {
if ($type->is_list) {
$key_values[] = new TLiteralInt(count($type->properties)); $key_values[] = new TLiteralInt(count($type->properties));
} else {
$init = -1;
foreach ($type->properties as $k => $_) {
if (is_int($k)) {
$init = $k;
}
}
$key_values[] = new TLiteralInt($init+1);
}
} }
if ($key_values) { if ($key_values) {
@ -1652,20 +1642,14 @@ class ArrayFetchAnalyzer
$offset_type->isMixed() ? Type::getArrayKey() : $offset_type->freeze() $offset_type->isMixed() ? Type::getArrayKey() : $offset_type->freeze()
); );
// Happens only if $type is an unsealed array or list
if (!$stmt->dim) { if (!$stmt->dim) {
assert($type->fallback_params !== null);
if ($type->is_list) { if ($type->is_list) {
if ($new_key_type !== $type->fallback_params[0]
|| $generic_params !== $type->fallback_params[1]
) {
$type = new TKeyedArray( $type = new TKeyedArray(
$type->properties, $type->properties,
null, null,
[$new_key_type, $generic_params], [$new_key_type, $generic_params],
true true
); );
}
} else { } else {
$type = new TNonEmptyArray([ $type = new TNonEmptyArray([
$new_key_type, $new_key_type,
@ -1673,12 +1657,18 @@ class ArrayFetchAnalyzer
], null, $type->getMinCount()+1); ], null, $type->getMinCount()+1);
} }
} else { } else {
$type = new TKeyedArray( $min_count = $type->getMinCount();
$type->properties, if ($min_count) {
null, $type = new TNonEmptyArray([
[$new_key_type, $generic_params], $new_key_type,
false $generic_params,
); ], null, $min_count);
} else {
$type = new TArray([
$new_key_type,
$generic_params,
]);
}
} }
$array_access_type = Type::combineUnionTypes( $array_access_type = Type::combineUnionTypes(