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:
parent
9b00ac0992
commit
cac5a1037a
@ -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 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] 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.
|
- [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.
|
||||||
|
|
||||||
|
@ -183,8 +183,6 @@ $a = [];
|
|||||||
foreach (range(1,1) as $_) $a[(string)rand(0,1)] = rand(0,1); // array<string,int>
|
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`.
|
`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
|
`TClassStringMap` - Represents an array where the type of each value is a function of its string key value
|
||||||
|
@ -39,7 +39,6 @@ use Psalm\Storage\MethodStorage;
|
|||||||
use Psalm\Type;
|
use Psalm\Type;
|
||||||
use Psalm\Type\Atomic\TArray;
|
use Psalm\Type\Atomic\TArray;
|
||||||
use Psalm\Type\Atomic\TCallable;
|
use Psalm\Type\Atomic\TCallable;
|
||||||
use Psalm\Type\Atomic\TCallableArray;
|
|
||||||
use Psalm\Type\Atomic\TCallableKeyedArray;
|
use Psalm\Type\Atomic\TCallableKeyedArray;
|
||||||
use Psalm\Type\Atomic\TClosure;
|
use Psalm\Type\Atomic\TClosure;
|
||||||
use Psalm\Type\Atomic\TKeyedArray;
|
use Psalm\Type\Atomic\TKeyedArray;
|
||||||
@ -1528,9 +1527,7 @@ class ArgumentsAnalyzer
|
|||||||
|
|
||||||
foreach ($arg_value_type->getAtomicTypes() as $atomic_arg_type) {
|
foreach ($arg_value_type->getAtomicTypes() as $atomic_arg_type) {
|
||||||
$packed_var_definite_args_tmp = [];
|
$packed_var_definite_args_tmp = [];
|
||||||
if ($atomic_arg_type instanceof TCallableArray ||
|
if ($atomic_arg_type instanceof TCallableKeyedArray) {
|
||||||
$atomic_arg_type instanceof TCallableKeyedArray
|
|
||||||
) {
|
|
||||||
$packed_var_definite_args_tmp[] = 2;
|
$packed_var_definite_args_tmp[] = 2;
|
||||||
} elseif ($atomic_arg_type instanceof TKeyedArray) {
|
} elseif ($atomic_arg_type instanceof TKeyedArray) {
|
||||||
if ($atomic_arg_type->fallback_params !== null) {
|
if ($atomic_arg_type->fallback_params !== null) {
|
||||||
|
@ -25,7 +25,6 @@ use Psalm\Storage\FunctionLikeStorage;
|
|||||||
use Psalm\Type;
|
use Psalm\Type;
|
||||||
use Psalm\Type\Atomic\TArray;
|
use Psalm\Type\Atomic\TArray;
|
||||||
use Psalm\Type\Atomic\TCallable;
|
use Psalm\Type\Atomic\TCallable;
|
||||||
use Psalm\Type\Atomic\TCallableArray;
|
|
||||||
use Psalm\Type\Atomic\TCallableKeyedArray;
|
use Psalm\Type\Atomic\TCallableKeyedArray;
|
||||||
use Psalm\Type\Atomic\TClassString;
|
use Psalm\Type\Atomic\TClassString;
|
||||||
use Psalm\Type\Atomic\TClosure;
|
use Psalm\Type\Atomic\TClosure;
|
||||||
@ -358,9 +357,7 @@ class FunctionCallReturnTypeFetcher
|
|||||||
|
|
||||||
if (count($atomic_types) === 1) {
|
if (count($atomic_types) === 1) {
|
||||||
if (isset($atomic_types['array'])) {
|
if (isset($atomic_types['array'])) {
|
||||||
if ($atomic_types['array'] instanceof TCallableArray
|
if ($atomic_types['array'] instanceof TCallableKeyedArray) {
|
||||||
|| $atomic_types['array'] instanceof TCallableKeyedArray
|
|
||||||
) {
|
|
||||||
return Type::getInt(false, 2);
|
return Type::getInt(false, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,8 +292,7 @@ final class HighOrderFunctionArgHandler
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($a instanceof Type\Atomic\TCallableArray ||
|
if ($a instanceof Type\Atomic\TCallableString ||
|
||||||
$a instanceof Type\Atomic\TCallableString ||
|
|
||||||
$a instanceof Type\Atomic\TCallableKeyedArray
|
$a instanceof Type\Atomic\TCallableKeyedArray
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -18,7 +18,6 @@ use Psalm\Type;
|
|||||||
use Psalm\Type\Atomic;
|
use Psalm\Type\Atomic;
|
||||||
use Psalm\Type\Atomic\TArray;
|
use Psalm\Type\Atomic\TArray;
|
||||||
use Psalm\Type\Atomic\TCallable;
|
use Psalm\Type\Atomic\TCallable;
|
||||||
use Psalm\Type\Atomic\TCallableArray;
|
|
||||||
use Psalm\Type\Atomic\TClassString;
|
use Psalm\Type\Atomic\TClassString;
|
||||||
use Psalm\Type\Atomic\TClosure;
|
use Psalm\Type\Atomic\TClosure;
|
||||||
use Psalm\Type\Atomic\TKeyedArray;
|
use Psalm\Type\Atomic\TKeyedArray;
|
||||||
@ -188,15 +187,6 @@ class CallableTypeComparator
|
|||||||
if (!$input_type_part->type_params[1]->hasString()) {
|
if (!$input_type_part->type_params[1]->hasString()) {
|
||||||
return false;
|
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) {
|
} elseif ($input_type_part instanceof TKeyedArray) {
|
||||||
$method_id = self::getCallableMethodIdFromTKeyedArray($input_type_part);
|
$method_id = self::getCallableMethodIdFromTKeyedArray($input_type_part);
|
||||||
|
|
||||||
|
@ -34,7 +34,6 @@ use Psalm\Type\Atomic\TArray;
|
|||||||
use Psalm\Type\Atomic\TArrayKey;
|
use Psalm\Type\Atomic\TArrayKey;
|
||||||
use Psalm\Type\Atomic\TBool;
|
use Psalm\Type\Atomic\TBool;
|
||||||
use Psalm\Type\Atomic\TCallable;
|
use Psalm\Type\Atomic\TCallable;
|
||||||
use Psalm\Type\Atomic\TCallableArray;
|
|
||||||
use Psalm\Type\Atomic\TCallableKeyedArray;
|
use Psalm\Type\Atomic\TCallableKeyedArray;
|
||||||
use Psalm\Type\Atomic\TCallableObject;
|
use Psalm\Type\Atomic\TCallableObject;
|
||||||
use Psalm\Type\Atomic\TCallableString;
|
use Psalm\Type\Atomic\TCallableString;
|
||||||
@ -2651,11 +2650,11 @@ class SimpleAssertionReconciler extends Reconciler
|
|||||||
) {
|
) {
|
||||||
$callable_types[] = $type;
|
$callable_types[] = $type;
|
||||||
$redundant = false;
|
$redundant = false;
|
||||||
} elseif ($type instanceof TArray) {
|
} /*elseif ($type instanceof TArray) {
|
||||||
$type = new TCallableArray($type->type_params);
|
$type = new TCallableArray($type->type_params);
|
||||||
$callable_types[] = $type;
|
$callable_types[] = $type;
|
||||||
$redundant = false;
|
$redundant = false;
|
||||||
} elseif ($type instanceof TKeyedArray && count($type->properties) === 2) {
|
} */elseif ($type instanceof TKeyedArray && count($type->properties) === 2) {
|
||||||
$type = new TCallableKeyedArray($type->properties);
|
$type = new TCallableKeyedArray($type->properties);
|
||||||
$callable_types[] = $type;
|
$callable_types[] = $type;
|
||||||
$redundant = false;
|
$redundant = false;
|
||||||
|
@ -26,7 +26,7 @@ use Psalm\Type\Atomic\TArray;
|
|||||||
use Psalm\Type\Atomic\TArrayKey;
|
use Psalm\Type\Atomic\TArrayKey;
|
||||||
use Psalm\Type\Atomic\TBool;
|
use Psalm\Type\Atomic\TBool;
|
||||||
use Psalm\Type\Atomic\TCallable;
|
use Psalm\Type\Atomic\TCallable;
|
||||||
use Psalm\Type\Atomic\TCallableArray;
|
use Psalm\Type\Atomic\TCallableKeyedArray;
|
||||||
use Psalm\Type\Atomic\TCallableObject;
|
use Psalm\Type\Atomic\TCallableObject;
|
||||||
use Psalm\Type\Atomic\TCallableString;
|
use Psalm\Type\Atomic\TCallableString;
|
||||||
use Psalm\Type\Atomic\TEmptyMixed;
|
use Psalm\Type\Atomic\TEmptyMixed;
|
||||||
@ -1187,7 +1187,7 @@ class SimpleNegatedAssertionReconciler extends Reconciler
|
|||||||
$non_object_types[] = $type;
|
$non_object_types[] = $type;
|
||||||
}
|
}
|
||||||
} elseif ($type instanceof TCallable) {
|
} elseif ($type instanceof TCallable) {
|
||||||
$non_object_types[] = new TCallableArray([
|
$non_object_types[] = new TCallableKeyedArray([
|
||||||
Type::getArrayKey(),
|
Type::getArrayKey(),
|
||||||
Type::getMixed(),
|
Type::getMixed(),
|
||||||
]);
|
]);
|
||||||
@ -1586,7 +1586,7 @@ class SimpleNegatedAssertionReconciler extends Reconciler
|
|||||||
$non_string_types[] = new TInt();
|
$non_string_types[] = new TInt();
|
||||||
$redundant = false;
|
$redundant = false;
|
||||||
} elseif ($type instanceof TCallable) {
|
} elseif ($type instanceof TCallable) {
|
||||||
$non_string_types[] = new TCallableArray([
|
$non_string_types[] = new TCallableKeyedArray([
|
||||||
Type::getArrayKey(),
|
Type::getArrayKey(),
|
||||||
Type::getMixed(),
|
Type::getMixed(),
|
||||||
]);
|
]);
|
||||||
|
@ -11,7 +11,6 @@ use Psalm\Type\Atomic\TArray;
|
|||||||
use Psalm\Type\Atomic\TArrayKey;
|
use Psalm\Type\Atomic\TArrayKey;
|
||||||
use Psalm\Type\Atomic\TBool;
|
use Psalm\Type\Atomic\TBool;
|
||||||
use Psalm\Type\Atomic\TCallable;
|
use Psalm\Type\Atomic\TCallable;
|
||||||
use Psalm\Type\Atomic\TCallableArray;
|
|
||||||
use Psalm\Type\Atomic\TCallableKeyedArray;
|
use Psalm\Type\Atomic\TCallableKeyedArray;
|
||||||
use Psalm\Type\Atomic\TCallableObject;
|
use Psalm\Type\Atomic\TCallableObject;
|
||||||
use Psalm\Type\Atomic\TCallableString;
|
use Psalm\Type\Atomic\TCallableString;
|
||||||
@ -400,7 +399,6 @@ class TypeCombiner
|
|||||||
bool $allow_mixed_union,
|
bool $allow_mixed_union,
|
||||||
int $literal_limit
|
int $literal_limit
|
||||||
): ?Union {
|
): ?Union {
|
||||||
|
|
||||||
if ($type instanceof TMixed) {
|
if ($type instanceof TMixed) {
|
||||||
if ($type->from_loop_isset) {
|
if ($type->from_loop_isset) {
|
||||||
if ($combination->mixed_from_loop_isset === null) {
|
if ($combination->mixed_from_loop_isset === null) {
|
||||||
@ -544,11 +542,17 @@ class TypeCombiner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($type instanceof TArray && $type_key === 'array') {
|
if ($type instanceof TCallableKeyedArray) {
|
||||||
if ($type instanceof TCallableArray && isset($combination->value_types['callable'])) {
|
if (isset($combination->value_types['callable'])) {
|
||||||
return null;
|
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) {
|
foreach ($type->type_params as $i => $type_param) {
|
||||||
// See https://github.com/vimeo/psalm/pull/9439#issuecomment-1464563015
|
// See https://github.com/vimeo/psalm/pull/9439#issuecomment-1464563015
|
||||||
/** @psalm-suppress PropertyTypeCoercion */
|
/** @psalm-suppress PropertyTypeCoercion */
|
||||||
@ -587,14 +591,6 @@ class TypeCombiner
|
|||||||
$combination->all_arrays_class_string_maps = false;
|
$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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1525,7 +1521,7 @@ class TypeCombiner
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($combination->all_arrays_callable) {
|
if ($combination->all_arrays_callable) {
|
||||||
$array_type = new TCallableArray($generic_type_params);
|
$array_type = new TCallableKeyedArray($generic_type_params);
|
||||||
} elseif ($combination->array_always_filled
|
} elseif ($combination->array_always_filled
|
||||||
|| ($combination->array_sometimes_filled && $overwrite_empty_array)
|
|| ($combination->array_sometimes_filled && $overwrite_empty_array)
|
||||||
|| ($combination->objectlike_entries
|
|| ($combination->objectlike_entries
|
||||||
|
@ -16,7 +16,6 @@ use Psalm\Type\Atomic\TArray;
|
|||||||
use Psalm\Type\Atomic\TArrayKey;
|
use Psalm\Type\Atomic\TArrayKey;
|
||||||
use Psalm\Type\Atomic\TBool;
|
use Psalm\Type\Atomic\TBool;
|
||||||
use Psalm\Type\Atomic\TCallable;
|
use Psalm\Type\Atomic\TCallable;
|
||||||
use Psalm\Type\Atomic\TCallableArray;
|
|
||||||
use Psalm\Type\Atomic\TCallableKeyedArray;
|
use Psalm\Type\Atomic\TCallableKeyedArray;
|
||||||
use Psalm\Type\Atomic\TCallableObject;
|
use Psalm\Type\Atomic\TCallableObject;
|
||||||
use Psalm\Type\Atomic\TCallableString;
|
use Psalm\Type\Atomic\TCallableString;
|
||||||
@ -258,7 +257,7 @@ abstract class Atomic implements TypeNode
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
case 'callable-array':
|
case 'callable-array':
|
||||||
return new TCallableArray([
|
return new TCallableKeyedArray([
|
||||||
new Union([new TArrayKey($from_docblock)]),
|
new Union([new TArrayKey($from_docblock)]),
|
||||||
new Union([new TMixed(false, $from_docblock)]),
|
new Union([new TMixed(false, $from_docblock)]),
|
||||||
]);
|
]);
|
||||||
@ -459,7 +458,6 @@ abstract class Atomic implements TypeNode
|
|||||||
return $this instanceof TCallable
|
return $this instanceof TCallable
|
||||||
|| $this instanceof TCallableObject
|
|| $this instanceof TCallableObject
|
||||||
|| $this instanceof TCallableString
|
|| $this instanceof TCallableString
|
||||||
|| $this instanceof TCallableArray
|
|
||||||
|| $this instanceof TCallableKeyedArray
|
|| $this instanceof TCallableKeyedArray
|
||||||
|| $this instanceof TClosure;
|
|| $this instanceof TClosure;
|
||||||
}
|
}
|
||||||
|
@ -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';
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user