mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 12:24:49 +01:00
only transform a Keyed array into callable-array if there's two elements (#5086)
* only transform a Keyed array into callable-array if there's two elements in array * add tests
This commit is contained in:
parent
c837535c9d
commit
c9129b5c4c
@ -40,6 +40,7 @@ use Psalm\Type\Atomic\TString;
|
||||
use Psalm\Type\Atomic\TTemplateParam;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
use function count;
|
||||
|
||||
class SimpleAssertionReconciler extends \Psalm\Type\Reconciler
|
||||
{
|
||||
@ -1988,7 +1989,7 @@ class SimpleAssertionReconciler extends \Psalm\Type\Reconciler
|
||||
$type = new TCallableList($type->type_param);
|
||||
$callable_types[] = $type;
|
||||
$did_remove_type = true;
|
||||
} elseif ($type instanceof TKeyedArray) {
|
||||
} elseif ($type instanceof TKeyedArray && count($type->properties) === 2) {
|
||||
$type = clone $type;
|
||||
$type = new TCallableKeyedArray($type->properties);
|
||||
$callable_types[] = $type;
|
||||
|
@ -126,6 +126,8 @@ class ReconcilerTest extends \Psalm\Tests\TestCase
|
||||
'iterableToArray' => ['array<int, int>', 'array', 'iterable<int, int>'],
|
||||
'iterableToTraversable' => ['Traversable<int, int>', 'Traversable', 'iterable<int, int>'],
|
||||
'callableToCallableArray' => ['callable-array{0: class-string|object, 1: string}', 'array', 'callable'],
|
||||
'SmallKeyedArrayAndCallable' => ['array{test: string}', 'array{test: string}', 'callable'],
|
||||
'BigKeyedArrayAndCallable' => ['array{foo: string, test: string, thing: string}', 'array{foo: string, test: string, thing: string}', 'callable'],
|
||||
'callableOrArrayToCallableArray' => ['array<array-key, mixed>', 'array', 'callable|array'],
|
||||
'traversableToIntersection' => ['Countable&Traversable', 'Traversable', 'Countable'],
|
||||
'iterableWithoutParamsToTraversableWithoutParams' => ['Traversable', '!array', 'iterable'],
|
||||
|
Loading…
Reference in New Issue
Block a user