diff --git a/src/Psalm/Internal/Type/Comparator/AtomicTypeComparator.php b/src/Psalm/Internal/Type/Comparator/AtomicTypeComparator.php index 85000bec7c7..15c4512429f 100644 --- a/src/Psalm/Internal/Type/Comparator/AtomicTypeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/AtomicTypeComparator.php @@ -8,7 +8,7 @@ use Psalm\Type\Atomic\Scalar; use Psalm\Type\Atomic\TArray; use Psalm\Type\Atomic\TCallable; -use Psalm\Type\Atomic\TCallableArray; +use Psalm\Type\Atomic\TCallableInterface; use Psalm\Type\Atomic\TCallableKeyedArray; use Psalm\Type\Atomic\TCallableObject; use Psalm\Type\Atomic\TCallableString; @@ -192,12 +192,8 @@ public static function isContainedBy( } if (($container_type_part instanceof TCallable - && ($input_type_part instanceof TCallable - || $input_type_part instanceof TCallableArray - || $input_type_part instanceof TCallableObject - || $input_type_part instanceof TCallableString - || $input_type_part instanceof TCallableKeyedArray - )) + && $input_type_part instanceof TCallableInterface + ) || ($container_type_part instanceof TClosure && $input_type_part instanceof TClosure) ) { diff --git a/src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php b/src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php index 393c8369167..5758dbb2499 100644 --- a/src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php @@ -19,9 +19,7 @@ use Psalm\Type\Atomic\TArray; 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\TCallableInterface; use Psalm\Type\Atomic\TClassString; use Psalm\Type\Atomic\TClosure; use Psalm\Type\Atomic\TKeyedArray; @@ -44,7 +42,7 @@ final class CallableTypeComparator { /** - * @param TCallable|TClosure|TCallableArray|TCallableString|TCallableKeyedArray|TCallableObject $input_type_part + * @param TClosure|TCallableInterface $input_type_part * @param TCallable|TClosure $container_type_part */ public static function isContainedBy( @@ -54,10 +52,8 @@ public static function isContainedBy( ?TypeComparisonResult $atomic_comparison_result ): bool { if ($container_type_part instanceof TClosure) { - if ($input_type_part instanceof TCallableArray - || $input_type_part instanceof TCallableString - || $input_type_part instanceof TCallableKeyedArray - || $input_type_part instanceof TCallableObject + if ($input_type_part instanceof TCallableInterface + && !$input_type_part instanceof TCallable // it has stricter checks below ) { if ($atomic_comparison_result) { $atomic_comparison_result->type_coerced = true; @@ -65,10 +61,8 @@ public static function isContainedBy( return false; } } - if ($input_type_part instanceof TCallableArray - || $input_type_part instanceof TCallableString - || $input_type_part instanceof TCallableKeyedArray - || $input_type_part instanceof TCallableObject + if ($input_type_part instanceof TCallableInterface + && !$input_type_part instanceof TCallable // it has stricter checks below ) { return true; } diff --git a/src/Psalm/Type/Atomic/TCallable.php b/src/Psalm/Type/Atomic/TCallable.php index 7ef847d4ab1..bcd925b2643 100644 --- a/src/Psalm/Type/Atomic/TCallable.php +++ b/src/Psalm/Type/Atomic/TCallable.php @@ -14,7 +14,7 @@ * * @psalm-immutable */ -final class TCallable extends Atomic +final class TCallable extends Atomic implements TCallableInterface { use CallableTrait; diff --git a/src/Psalm/Type/Atomic/TCallableArray.php b/src/Psalm/Type/Atomic/TCallableArray.php index d4992523b06..695a9d0e8b9 100644 --- a/src/Psalm/Type/Atomic/TCallableArray.php +++ b/src/Psalm/Type/Atomic/TCallableArray.php @@ -7,7 +7,7 @@ * * @psalm-immutable */ -final class TCallableArray extends TNonEmptyArray +final class TCallableArray extends TNonEmptyArray implements TCallableInterface { /** * @var string diff --git a/src/Psalm/Type/Atomic/TCallableInterface.php b/src/Psalm/Type/Atomic/TCallableInterface.php new file mode 100644 index 00000000000..e25f076d1a7 --- /dev/null +++ b/src/Psalm/Type/Atomic/TCallableInterface.php @@ -0,0 +1,7 @@ +