From 80eab1b0625e2f66e67ec4d57847ce5715509da4 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 21 Nov 2022 19:37:06 +0100 Subject: [PATCH] Update --- src/Psalm/Type/Atomic/GenericTrait.php | 4 ---- src/Psalm/Type/Atomic/TCallableList.php | 12 ------------ src/Psalm/Type/Atomic/TKeyOf.php | 3 --- src/Psalm/Type/Atomic/TKeyedArray.php | 9 ++++++++- src/Psalm/Type/Atomic/TValueOf.php | 3 --- src/Psalm/Type/Reconciler.php | 17 ----------------- src/Psalm/Type/UnionTrait.php | 5 ++++- 7 files changed, 12 insertions(+), 41 deletions(-) delete mode 100644 src/Psalm/Type/Atomic/TCallableList.php diff --git a/src/Psalm/Type/Atomic/GenericTrait.php b/src/Psalm/Type/Atomic/GenericTrait.php index 9167c0644..d4568475f 100644 --- a/src/Psalm/Type/Atomic/GenericTrait.php +++ b/src/Psalm/Type/Atomic/GenericTrait.php @@ -172,10 +172,6 @@ trait GenericTrait bool $add_lower_bound = false, int $depth = 0 ): ?array { - if ($input_type instanceof TList) { - $input_type = new TArray([Type::getInt(), $input_type->type_param]); - } - $input_object_type_params = []; $container_type_params_covariant = []; diff --git a/src/Psalm/Type/Atomic/TCallableList.php b/src/Psalm/Type/Atomic/TCallableList.php deleted file mode 100644 index 67c490e17..000000000 --- a/src/Psalm/Type/Atomic/TCallableList.php +++ /dev/null @@ -1,12 +0,0 @@ -getAtomicTypes() as $atomic_type) { if ($atomic_type instanceof TArray) { $array_key_atomics = $atomic_type->type_params[0]; - } elseif ($atomic_type instanceof TList) { - $array_key_atomics = Type::getInt(); } elseif ($atomic_type instanceof TKeyedArray) { $array_key_atomics = $atomic_type->getGenericKeyType(); } elseif ($atomic_type instanceof TTemplateParam) { diff --git a/src/Psalm/Type/Atomic/TKeyedArray.php b/src/Psalm/Type/Atomic/TKeyedArray.php index a0c263e40..179103f41 100644 --- a/src/Psalm/Type/Atomic/TKeyedArray.php +++ b/src/Psalm/Type/Atomic/TKeyedArray.php @@ -244,6 +244,13 @@ class TKeyedArray extends Atomic public function getGenericKeyType(bool $possibly_undefined = false): Union { + if ($this->is_list) { + if ($this->fallback_params === null) { + return new Union([new TIntRange(0, count($this->properties))]); + } + return new Union([new TIntRange(0, null)]); + } + $key_types = []; foreach ($this->properties as $key => $_) { @@ -311,7 +318,7 @@ class TKeyedArray extends Atomic $value_type = Type::combineUnionTypes($property, $value_type); if (!$property->possibly_undefined) { - $has_defined_keys++; + $has_defined_keys = true; } } diff --git a/src/Psalm/Type/Atomic/TValueOf.php b/src/Psalm/Type/Atomic/TValueOf.php index 486021b82..560c153fa 100644 --- a/src/Psalm/Type/Atomic/TValueOf.php +++ b/src/Psalm/Type/Atomic/TValueOf.php @@ -61,7 +61,6 @@ final class TValueOf extends Atomic if (!$type instanceof TArray && !$type instanceof TClassConstant && !$type instanceof TKeyedArray - && !$type instanceof TList && !$type instanceof TPropertiesOf && !$type instanceof TNamedObject ) { @@ -81,8 +80,6 @@ final class TValueOf extends Atomic foreach ($type->getAtomicTypes() as $atomic_type) { if ($atomic_type instanceof TArray) { $value_atomics = $atomic_type->type_params[1]; - } elseif ($atomic_type instanceof TList) { - $value_atomics = $atomic_type->type_param; } elseif ($atomic_type instanceof TKeyedArray) { $value_atomics = $atomic_type->getGenericValueType(); } elseif ($atomic_type instanceof TTemplateParam) { diff --git a/src/Psalm/Type/Reconciler.php b/src/Psalm/Type/Reconciler.php index d0aefbd8e..9730e2eea 100644 --- a/src/Psalm/Type/Reconciler.php +++ b/src/Psalm/Type/Reconciler.php @@ -715,23 +715,6 @@ class Reconciler return $new_base_type_candidate; } - if (($has_isset || $has_inverted_isset) && isset($new_assertions[$new_base_key])) { - if ($has_inverted_isset && $new_base_key === $key) { - $new_base_type_candidate = $new_base_type_candidate->getBuilder(); - $new_base_type_candidate->addType(new TNull); - $new_base_type_candidate->possibly_undefined = true; - $new_base_type_candidate = $new_base_type_candidate->freeze(); - } else { - $new_base_type_candidate = $new_base_type_candidate->setPossiblyUndefined(true); - } - } - } elseif ($existing_key_type_part instanceof TList) { - if ($has_empty) { - return null; - } - - $new_base_type_candidate = $existing_key_type_part->type_param; - if (($has_isset || $has_inverted_isset) && isset($new_assertions[$new_base_key])) { if ($has_inverted_isset && $new_base_key === $key) { $new_base_type_candidate = $new_base_type_candidate->getBuilder(); diff --git a/src/Psalm/Type/UnionTrait.php b/src/Psalm/Type/UnionTrait.php index fe84bd744..c2528a04d 100644 --- a/src/Psalm/Type/UnionTrait.php +++ b/src/Psalm/Type/UnionTrait.php @@ -24,6 +24,7 @@ use Psalm\Type\Atomic\TEmptyMixed; use Psalm\Type\Atomic\TFalse; use Psalm\Type\Atomic\TInt; use Psalm\Type\Atomic\TIntRange; +use Psalm\Type\Atomic\TKeyedArray; use Psalm\Type\Atomic\TList; use Psalm\Type\Atomic\TLiteralFloat; use Psalm\Type\Atomic\TLiteralInt; @@ -409,7 +410,9 @@ trait UnionTrait */ public function hasList(): bool { - return isset($this->types['array']) && $this->types['array'] instanceof TList; + return isset($this->types['array']) + && $this->types['array'] instanceof TKeyedArray + && $this->types['array']->is_list; } /**