1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 17:52:45 +01:00
This commit is contained in:
Daniil Gentili 2022-11-28 11:58:05 +01:00
parent c156807eca
commit 42380dbe87
2 changed files with 8 additions and 3 deletions

View File

@ -15,6 +15,7 @@ use Psalm\Internal\Analyzer\TraitAnalyzer;
use Psalm\Internal\Codebase\TaintFlowGraph;
use Psalm\Internal\Codebase\VariableUseGraph;
use Psalm\Internal\DataFlow\DataFlowNode;
use Psalm\Internal\Type\Comparator\AtomicTypeComparator;
use Psalm\Internal\Type\Comparator\TypeComparisonResult;
use Psalm\Internal\Type\Comparator\UnionTypeComparator;
use Psalm\Internal\Type\TemplateInferredTypeReplacer;
@ -1514,7 +1515,11 @@ class ArrayFetchAnalyzer
if ($type->is_list && (!is_numeric($key_value->value) || $key_value->value < 0)) {
$expected_offset_types[] = $type->getGenericKeyType();
$has_valid_offset = false;
} elseif (isset($properties[$key_value->value]) || $replacement_type) {
} elseif ((isset($properties[$key_value->value]) && !(
$key_value->value === 0 && AtomicTypeComparator::isLegacyTListLike($type)
))
|| $replacement_type
) {
$has_valid_offset = true;
if ($replacement_type) {

View File

@ -729,7 +729,7 @@ class AtomicTypeComparator
return $input_type_part->getKey() === $container_type_part->getKey();
}
private static function isLegacyTListLike(Atomic $array): bool
public static function isLegacyTListLike(Atomic $array): bool
{
return $array instanceof TKeyedArray
&& $array->is_list
@ -739,7 +739,7 @@ class AtomicTypeComparator
&& $array->properties[0]->equals($array->fallback_params[1], true, true, false)
;
}
private static function isLegacyTNonEmptyListLike(Atomic $array): bool
public static function isLegacyTNonEmptyListLike(Atomic $array): bool
{
return $array instanceof TKeyedArray
&& $array->is_list