1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-03 18:17:55 +01:00
This commit is contained in:
Daniil Gentili 2022-11-21 19:37:06 +01:00
parent 3f5f98b9d3
commit 80eab1b062
7 changed files with 12 additions and 41 deletions

View File

@ -172,10 +172,6 @@ trait GenericTrait
bool $add_lower_bound = false, bool $add_lower_bound = false,
int $depth = 0 int $depth = 0
): ?array { ): ?array {
if ($input_type instanceof TList) {
$input_type = new TArray([Type::getInt(), $input_type->type_param]);
}
$input_object_type_params = []; $input_object_type_params = [];
$container_type_params_covariant = []; $container_type_params_covariant = [];

View File

@ -1,12 +0,0 @@
<?php
namespace Psalm\Type\Atomic;
/**
* Denotes a list that is _also_ `callable`.
* @psalm-immutable
*/
final class TCallableList extends TNonEmptyList
{
public const KEY = 'callable-list';
}

View File

@ -56,7 +56,6 @@ final class TKeyOf extends TArrayKey
if (!$type instanceof TArray if (!$type instanceof TArray
&& !$type instanceof TClassConstant && !$type instanceof TClassConstant
&& !$type instanceof TKeyedArray && !$type instanceof TKeyedArray
&& !$type instanceof TList
&& !$type instanceof TPropertiesOf && !$type instanceof TPropertiesOf
) { ) {
return false; return false;
@ -74,8 +73,6 @@ final class TKeyOf extends TArrayKey
foreach ($type->getAtomicTypes() as $atomic_type) { foreach ($type->getAtomicTypes() as $atomic_type) {
if ($atomic_type instanceof TArray) { if ($atomic_type instanceof TArray) {
$array_key_atomics = $atomic_type->type_params[0]; $array_key_atomics = $atomic_type->type_params[0];
} elseif ($atomic_type instanceof TList) {
$array_key_atomics = Type::getInt();
} elseif ($atomic_type instanceof TKeyedArray) { } elseif ($atomic_type instanceof TKeyedArray) {
$array_key_atomics = $atomic_type->getGenericKeyType(); $array_key_atomics = $atomic_type->getGenericKeyType();
} elseif ($atomic_type instanceof TTemplateParam) { } elseif ($atomic_type instanceof TTemplateParam) {

View File

@ -244,6 +244,13 @@ 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->fallback_params === null) {
return new Union([new TIntRange(0, count($this->properties))]);
}
return new Union([new TIntRange(0, null)]);
}
$key_types = []; $key_types = [];
foreach ($this->properties as $key => $_) { foreach ($this->properties as $key => $_) {
@ -311,7 +318,7 @@ class TKeyedArray extends Atomic
$value_type = Type::combineUnionTypes($property, $value_type); $value_type = Type::combineUnionTypes($property, $value_type);
if (!$property->possibly_undefined) { if (!$property->possibly_undefined) {
$has_defined_keys++; $has_defined_keys = true;
} }
} }

View File

@ -61,7 +61,6 @@ final class TValueOf extends Atomic
if (!$type instanceof TArray if (!$type instanceof TArray
&& !$type instanceof TClassConstant && !$type instanceof TClassConstant
&& !$type instanceof TKeyedArray && !$type instanceof TKeyedArray
&& !$type instanceof TList
&& !$type instanceof TPropertiesOf && !$type instanceof TPropertiesOf
&& !$type instanceof TNamedObject && !$type instanceof TNamedObject
) { ) {
@ -81,8 +80,6 @@ final class TValueOf extends Atomic
foreach ($type->getAtomicTypes() as $atomic_type) { foreach ($type->getAtomicTypes() as $atomic_type) {
if ($atomic_type instanceof TArray) { if ($atomic_type instanceof TArray) {
$value_atomics = $atomic_type->type_params[1]; $value_atomics = $atomic_type->type_params[1];
} elseif ($atomic_type instanceof TList) {
$value_atomics = $atomic_type->type_param;
} elseif ($atomic_type instanceof TKeyedArray) { } elseif ($atomic_type instanceof TKeyedArray) {
$value_atomics = $atomic_type->getGenericValueType(); $value_atomics = $atomic_type->getGenericValueType();
} elseif ($atomic_type instanceof TTemplateParam) { } elseif ($atomic_type instanceof TTemplateParam) {

View File

@ -715,23 +715,6 @@ class Reconciler
return $new_base_type_candidate; 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_isset || $has_inverted_isset) && isset($new_assertions[$new_base_key])) {
if ($has_inverted_isset && $new_base_key === $key) { if ($has_inverted_isset && $new_base_key === $key) {
$new_base_type_candidate = $new_base_type_candidate->getBuilder(); $new_base_type_candidate = $new_base_type_candidate->getBuilder();

View File

@ -24,6 +24,7 @@ use Psalm\Type\Atomic\TEmptyMixed;
use Psalm\Type\Atomic\TFalse; use Psalm\Type\Atomic\TFalse;
use Psalm\Type\Atomic\TInt; use Psalm\Type\Atomic\TInt;
use Psalm\Type\Atomic\TIntRange; use Psalm\Type\Atomic\TIntRange;
use Psalm\Type\Atomic\TKeyedArray;
use Psalm\Type\Atomic\TList; use Psalm\Type\Atomic\TList;
use Psalm\Type\Atomic\TLiteralFloat; use Psalm\Type\Atomic\TLiteralFloat;
use Psalm\Type\Atomic\TLiteralInt; use Psalm\Type\Atomic\TLiteralInt;
@ -409,7 +410,9 @@ trait UnionTrait
*/ */
public function hasList(): bool 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;
} }
/** /**