diff --git a/UPGRADING.md b/UPGRADING.md index d7c70b165..c87c1fc4e 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -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. diff --git a/docs/running_psalm/plugins/plugins_type_system.md b/docs/running_psalm/plugins/plugins_type_system.md index 5cf70ad94..99e6fa6b8 100644 --- a/docs/running_psalm/plugins/plugins_type_system.md +++ b/docs/running_psalm/plugins/plugins_type_system.md @@ -183,8 +183,6 @@ $a = []; foreach (range(1,1) as $_) $a[(string)rand(0,1)] = rand(0,1); // array ``` -`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 diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php index cbaab782d..cebfd09dd 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php @@ -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) { diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php index 943567b6f..61b90ca98 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php @@ -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); } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgHandler.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgHandler.php index 3d1a51c4e..1f43ee903 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgHandler.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/HighOrderFunctionArgHandler.php @@ -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; diff --git a/src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php b/src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php index 84dd4616c..89fe33627 100644 --- a/src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php @@ -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); diff --git a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php index 76ea3a998..35ed8ea8f 100644 --- a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php @@ -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; diff --git a/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php index 26955bf6d..93eaf8a90 100644 --- a/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php @@ -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(), ]); diff --git a/src/Psalm/Internal/Type/TypeCombiner.php b/src/Psalm/Internal/Type/TypeCombiner.php index b32ad3b3d..e1dbd1b63 100644 --- a/src/Psalm/Internal/Type/TypeCombiner.php +++ b/src/Psalm/Internal/Type/TypeCombiner.php @@ -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 diff --git a/src/Psalm/Type/Atomic.php b/src/Psalm/Type/Atomic.php index 222416cfe..c2b12b23d 100644 --- a/src/Psalm/Type/Atomic.php +++ b/src/Psalm/Type/Atomic.php @@ -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; } diff --git a/src/Psalm/Type/Atomic/TCallableArray.php b/src/Psalm/Type/Atomic/TCallableArray.php deleted file mode 100644 index d4992523b..000000000 --- a/src/Psalm/Type/Atomic/TCallableArray.php +++ /dev/null @@ -1,16 +0,0 @@ -