1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-04 18:48:03 +01:00
This commit is contained in:
Daniil Gentili 2022-11-26 18:15:50 +01:00
parent 156d629fbe
commit a342a26f0d
3 changed files with 6 additions and 10 deletions

View File

@ -621,7 +621,7 @@ class ArrayAssignmentAnalyzer
), ),
null, null,
[ [
new Union([new TIntRange($prop_count, null)]), new Union([new TIntRange(0, null)]),
$array_atomic_type_list $array_atomic_type_list
], ],
true true
@ -650,7 +650,7 @@ class ArrayAssignmentAnalyzer
), ),
null, null,
[ [
new Union([new TIntRange(count($atomic_root_types['array']->properties), null)]), new Union([new TIntRange(0, null)]),
$array_atomic_type_list $array_atomic_type_list
], ],
true true

View File

@ -1501,7 +1501,7 @@ class TypeCombiner
$array_type = new TKeyedArray( $array_type = new TKeyedArray(
$properties, $properties,
null, null,
[new Union([new TIntRange($cnt, null)]), $generic_type_params[1]], [new Union([new TIntRange(0, null)]), $generic_type_params[1]],
true true
); );
} }

View File

@ -257,7 +257,7 @@ class TKeyedArray extends Atomic
public function getGenericKeyType(bool $possibly_undefined = false): Union public function getGenericKeyType(bool $possibly_undefined = false): Union
{ {
if ($this->is_list) { if ($this->is_list) {
return new Union([new TIntRange($this->getMinCount(), $this->getMaxCount())]); return new Union([new TIntRange(0, $this->getMaxCount())]);
} }
$key_types = []; $key_types = [];
@ -313,12 +313,8 @@ class TKeyedArray extends Atomic
$has_defined_keys = false; $has_defined_keys = false;
$min_count = 0;
foreach ($this->properties as $key => $property) { foreach ($this->properties as $key => $property) {
if ($this->is_list) { if ($this->is_list) {
if (!$property->possibly_undefined) {
$min_count++;
}
// Do nothing // Do nothing
} elseif (is_int($key)) { } elseif (is_int($key)) {
$key_types[] = new TLiteralInt($key); $key_types[] = new TLiteralInt($key);
@ -343,9 +339,9 @@ class TKeyedArray extends Atomic
$value_type = $value_type->setPossiblyUndefined(false); $value_type = $value_type->setPossiblyUndefined(false);
if ($this->fallback_params === null) { if ($this->fallback_params === null) {
$key_type = new Union([new TIntRange($min_count, count($this->properties), false, $list_var_id)]); $key_type = new Union([new TIntRange(0, count($this->properties), false, $list_var_id)]);
} else { } else {
$key_type = new Union([new TIntRange($min_count, null, false, $list_var_id)]); $key_type = new Union([new TIntRange(0, null, false, $list_var_id)]);
} }
if ($has_defined_keys) { if ($has_defined_keys) {