1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Remove TCallableArray and TCallableList

This commit is contained in:
RobChett 2023-05-14 22:58:33 +01:00 committed by robchett
parent 9b00ac0992
commit cac5a1037a
11 changed files with 20 additions and 61 deletions

View File

@ -10,6 +10,7 @@
- [BC] The only optional boolean parameter of `TKeyedArray::getGenericArrayType` was removed, and was replaced with a string parameter with a different meaning.
- [BC] The `TDependentListKey` type was removed and replaced with an optional property of the `TIntRange` type.
- [BC] `TCallableArray` and `TCallableList` removed and replaced with `TCallableKeyedArray`.
- [BC] Value of constant `Psalm\Type\TaintKindGroup::ALL_INPUT` changed to reflect new `TaintKind::INPUT_SLEEP` and `TaintKind::INPUT_XPATH` have been added. Accordingly, default values for `$taint` parameters of `Psalm\Codebase::addTaintSource()` and `Psalm\Codebase::addTaintSink()` have been changed as well.

View File

@ -183,8 +183,6 @@ $a = [];
foreach (range(1,1) as $_) $a[(string)rand(0,1)] = rand(0,1); // array<string,int>
```
`TCallableArray` - denotes an array that is _also_ `callable`.
`TCallableKeyedArray` - denotes an object-like array that is _also_ `callable`.
`TClassStringMap` - Represents an array where the type of each value is a function of its string key value

View File

@ -39,7 +39,6 @@ use Psalm\Storage\MethodStorage;
use Psalm\Type;
use Psalm\Type\Atomic\TArray;
use Psalm\Type\Atomic\TCallable;
use Psalm\Type\Atomic\TCallableArray;
use Psalm\Type\Atomic\TCallableKeyedArray;
use Psalm\Type\Atomic\TClosure;
use Psalm\Type\Atomic\TKeyedArray;
@ -1528,9 +1527,7 @@ class ArgumentsAnalyzer
foreach ($arg_value_type->getAtomicTypes() as $atomic_arg_type) {
$packed_var_definite_args_tmp = [];
if ($atomic_arg_type instanceof TCallableArray ||
$atomic_arg_type instanceof TCallableKeyedArray
) {
if ($atomic_arg_type instanceof TCallableKeyedArray) {
$packed_var_definite_args_tmp[] = 2;
} elseif ($atomic_arg_type instanceof TKeyedArray) {
if ($atomic_arg_type->fallback_params !== null) {

View File

@ -25,7 +25,6 @@ use Psalm\Storage\FunctionLikeStorage;
use Psalm\Type;
use Psalm\Type\Atomic\TArray;
use Psalm\Type\Atomic\TCallable;
use Psalm\Type\Atomic\TCallableArray;
use Psalm\Type\Atomic\TCallableKeyedArray;
use Psalm\Type\Atomic\TClassString;
use Psalm\Type\Atomic\TClosure;
@ -358,9 +357,7 @@ class FunctionCallReturnTypeFetcher
if (count($atomic_types) === 1) {
if (isset($atomic_types['array'])) {
if ($atomic_types['array'] instanceof TCallableArray
|| $atomic_types['array'] instanceof TCallableKeyedArray
) {
if ($atomic_types['array'] instanceof TCallableKeyedArray) {
return Type::getInt(false, 2);
}

View File

@ -292,8 +292,7 @@ final class HighOrderFunctionArgHandler
return false;
}
if ($a instanceof Type\Atomic\TCallableArray ||
$a instanceof Type\Atomic\TCallableString ||
if ($a instanceof Type\Atomic\TCallableString ||
$a instanceof Type\Atomic\TCallableKeyedArray
) {
return false;

View File

@ -18,7 +18,6 @@ use Psalm\Type;
use Psalm\Type\Atomic;
use Psalm\Type\Atomic\TArray;
use Psalm\Type\Atomic\TCallable;
use Psalm\Type\Atomic\TCallableArray;
use Psalm\Type\Atomic\TClassString;
use Psalm\Type\Atomic\TClosure;
use Psalm\Type\Atomic\TKeyedArray;
@ -188,15 +187,6 @@ class CallableTypeComparator
if (!$input_type_part->type_params[1]->hasString()) {
return false;
}
if (!$input_type_part instanceof TCallableArray) {
if ($atomic_comparison_result) {
$atomic_comparison_result->type_coerced_from_mixed = true;
$atomic_comparison_result->type_coerced = true;
}
return false;
}
} elseif ($input_type_part instanceof TKeyedArray) {
$method_id = self::getCallableMethodIdFromTKeyedArray($input_type_part);

View File

@ -34,7 +34,6 @@ use Psalm\Type\Atomic\TArray;
use Psalm\Type\Atomic\TArrayKey;
use Psalm\Type\Atomic\TBool;
use Psalm\Type\Atomic\TCallable;
use Psalm\Type\Atomic\TCallableArray;
use Psalm\Type\Atomic\TCallableKeyedArray;
use Psalm\Type\Atomic\TCallableObject;
use Psalm\Type\Atomic\TCallableString;
@ -2651,11 +2650,11 @@ class SimpleAssertionReconciler extends Reconciler
) {
$callable_types[] = $type;
$redundant = false;
} elseif ($type instanceof TArray) {
} /*elseif ($type instanceof TArray) {
$type = new TCallableArray($type->type_params);
$callable_types[] = $type;
$redundant = false;
} elseif ($type instanceof TKeyedArray && count($type->properties) === 2) {
} */elseif ($type instanceof TKeyedArray && count($type->properties) === 2) {
$type = new TCallableKeyedArray($type->properties);
$callable_types[] = $type;
$redundant = false;

View File

@ -26,7 +26,7 @@ use Psalm\Type\Atomic\TArray;
use Psalm\Type\Atomic\TArrayKey;
use Psalm\Type\Atomic\TBool;
use Psalm\Type\Atomic\TCallable;
use Psalm\Type\Atomic\TCallableArray;
use Psalm\Type\Atomic\TCallableKeyedArray;
use Psalm\Type\Atomic\TCallableObject;
use Psalm\Type\Atomic\TCallableString;
use Psalm\Type\Atomic\TEmptyMixed;
@ -1187,7 +1187,7 @@ class SimpleNegatedAssertionReconciler extends Reconciler
$non_object_types[] = $type;
}
} elseif ($type instanceof TCallable) {
$non_object_types[] = new TCallableArray([
$non_object_types[] = new TCallableKeyedArray([
Type::getArrayKey(),
Type::getMixed(),
]);
@ -1586,7 +1586,7 @@ class SimpleNegatedAssertionReconciler extends Reconciler
$non_string_types[] = new TInt();
$redundant = false;
} elseif ($type instanceof TCallable) {
$non_string_types[] = new TCallableArray([
$non_string_types[] = new TCallableKeyedArray([
Type::getArrayKey(),
Type::getMixed(),
]);

View File

@ -11,7 +11,6 @@ use Psalm\Type\Atomic\TArray;
use Psalm\Type\Atomic\TArrayKey;
use Psalm\Type\Atomic\TBool;
use Psalm\Type\Atomic\TCallable;
use Psalm\Type\Atomic\TCallableArray;
use Psalm\Type\Atomic\TCallableKeyedArray;
use Psalm\Type\Atomic\TCallableObject;
use Psalm\Type\Atomic\TCallableString;
@ -400,7 +399,6 @@ class TypeCombiner
bool $allow_mixed_union,
int $literal_limit
): ?Union {
if ($type instanceof TMixed) {
if ($type->from_loop_isset) {
if ($combination->mixed_from_loop_isset === null) {
@ -544,11 +542,17 @@ class TypeCombiner
}
}
if ($type instanceof TArray && $type_key === 'array') {
if ($type instanceof TCallableArray && isset($combination->value_types['callable'])) {
if ($type instanceof TCallableKeyedArray) {
if (isset($combination->value_types['callable'])) {
return null;
}
if ($combination->all_arrays_callable !== false) {
$combination->all_arrays_callable = true;
} else {
$combination->all_arrays_callable = false;
}
}
if ($type instanceof TArray && $type_key === 'array') {
foreach ($type->type_params as $i => $type_param) {
// See https://github.com/vimeo/psalm/pull/9439#issuecomment-1464563015
/** @psalm-suppress PropertyTypeCoercion */
@ -587,14 +591,6 @@ class TypeCombiner
$combination->all_arrays_class_string_maps = false;
}
if ($type instanceof TCallableArray) {
if ($combination->all_arrays_callable !== false) {
$combination->all_arrays_callable = true;
}
} else {
$combination->all_arrays_callable = false;
}
return null;
}
@ -1525,7 +1521,7 @@ class TypeCombiner
}
if ($combination->all_arrays_callable) {
$array_type = new TCallableArray($generic_type_params);
$array_type = new TCallableKeyedArray($generic_type_params);
} elseif ($combination->array_always_filled
|| ($combination->array_sometimes_filled && $overwrite_empty_array)
|| ($combination->objectlike_entries

View File

@ -16,7 +16,6 @@ use Psalm\Type\Atomic\TArray;
use Psalm\Type\Atomic\TArrayKey;
use Psalm\Type\Atomic\TBool;
use Psalm\Type\Atomic\TCallable;
use Psalm\Type\Atomic\TCallableArray;
use Psalm\Type\Atomic\TCallableKeyedArray;
use Psalm\Type\Atomic\TCallableObject;
use Psalm\Type\Atomic\TCallableString;
@ -258,7 +257,7 @@ abstract class Atomic implements TypeNode
]);
case 'callable-array':
return new TCallableArray([
return new TCallableKeyedArray([
new Union([new TArrayKey($from_docblock)]),
new Union([new TMixed(false, $from_docblock)]),
]);
@ -459,7 +458,6 @@ abstract class Atomic implements TypeNode
return $this instanceof TCallable
|| $this instanceof TCallableObject
|| $this instanceof TCallableString
|| $this instanceof TCallableArray
|| $this instanceof TCallableKeyedArray
|| $this instanceof TClosure;
}

View File

@ -1,16 +0,0 @@
<?php
namespace Psalm\Type\Atomic;
/**
* Denotes an array that is _also_ `callable`.
*
* @psalm-immutable
*/
final class TCallableArray extends TNonEmptyArray
{
/**
* @var string
*/
public $value = 'callable-array';
}