From a342a26f0d923abc590d4438f5dcf694eaad401d Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 26 Nov 2022 18:15:50 +0100 Subject: [PATCH] Fix --- .../Expression/Assignment/ArrayAssignmentAnalyzer.php | 4 ++-- src/Psalm/Internal/Type/TypeCombiner.php | 2 +- src/Psalm/Type/Atomic/TKeyedArray.php | 10 +++------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/ArrayAssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/ArrayAssignmentAnalyzer.php index ab063bfed..fb81086ed 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/ArrayAssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/ArrayAssignmentAnalyzer.php @@ -621,7 +621,7 @@ class ArrayAssignmentAnalyzer ), null, [ - new Union([new TIntRange($prop_count, null)]), + new Union([new TIntRange(0, null)]), $array_atomic_type_list ], true @@ -650,7 +650,7 @@ class ArrayAssignmentAnalyzer ), null, [ - new Union([new TIntRange(count($atomic_root_types['array']->properties), null)]), + new Union([new TIntRange(0, null)]), $array_atomic_type_list ], true diff --git a/src/Psalm/Internal/Type/TypeCombiner.php b/src/Psalm/Internal/Type/TypeCombiner.php index 891f9faac..6a2f77d01 100644 --- a/src/Psalm/Internal/Type/TypeCombiner.php +++ b/src/Psalm/Internal/Type/TypeCombiner.php @@ -1501,7 +1501,7 @@ class TypeCombiner $array_type = new TKeyedArray( $properties, null, - [new Union([new TIntRange($cnt, null)]), $generic_type_params[1]], + [new Union([new TIntRange(0, null)]), $generic_type_params[1]], true ); } diff --git a/src/Psalm/Type/Atomic/TKeyedArray.php b/src/Psalm/Type/Atomic/TKeyedArray.php index 763ec35ba..a938515d6 100644 --- a/src/Psalm/Type/Atomic/TKeyedArray.php +++ b/src/Psalm/Type/Atomic/TKeyedArray.php @@ -257,7 +257,7 @@ class TKeyedArray extends Atomic public function getGenericKeyType(bool $possibly_undefined = false): Union { if ($this->is_list) { - return new Union([new TIntRange($this->getMinCount(), $this->getMaxCount())]); + return new Union([new TIntRange(0, $this->getMaxCount())]); } $key_types = []; @@ -313,12 +313,8 @@ class TKeyedArray extends Atomic $has_defined_keys = false; - $min_count = 0; foreach ($this->properties as $key => $property) { if ($this->is_list) { - if (!$property->possibly_undefined) { - $min_count++; - } // Do nothing } elseif (is_int($key)) { $key_types[] = new TLiteralInt($key); @@ -343,9 +339,9 @@ class TKeyedArray extends Atomic $value_type = $value_type->setPossiblyUndefined(false); 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 { - $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) {