mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 22:01:48 +01:00
Merge pull request #7470 from orklah/array_is_list2
reconcile two arrays by intersecting them
This commit is contained in:
commit
5e41e1445e
@ -23,6 +23,8 @@ use Psalm\Type\Atomic\TFalse;
|
|||||||
use Psalm\Type\Atomic\TFloat;
|
use Psalm\Type\Atomic\TFloat;
|
||||||
use Psalm\Type\Atomic\TInt;
|
use Psalm\Type\Atomic\TInt;
|
||||||
use Psalm\Type\Atomic\TIterable;
|
use Psalm\Type\Atomic\TIterable;
|
||||||
|
use Psalm\Type\Atomic\TKeyedArray;
|
||||||
|
use Psalm\Type\Atomic\TList;
|
||||||
use Psalm\Type\Atomic\TLiteralFloat;
|
use Psalm\Type\Atomic\TLiteralFloat;
|
||||||
use Psalm\Type\Atomic\TLiteralInt;
|
use Psalm\Type\Atomic\TLiteralInt;
|
||||||
use Psalm\Type\Atomic\TLiteralString;
|
use Psalm\Type\Atomic\TLiteralString;
|
||||||
@ -33,6 +35,8 @@ use Psalm\Type\Atomic\TTrue;
|
|||||||
use Psalm\Type\Reconciler;
|
use Psalm\Type\Reconciler;
|
||||||
use Psalm\Type\Union;
|
use Psalm\Type\Union;
|
||||||
|
|
||||||
|
use function array_merge;
|
||||||
|
use function array_values;
|
||||||
use function count;
|
use function count;
|
||||||
use function get_class;
|
use function get_class;
|
||||||
use function strtolower;
|
use function strtolower;
|
||||||
@ -162,6 +166,8 @@ class NegatedAssertionReconciler extends Reconciler
|
|||||||
return $existing_var_type;
|
return $existing_var_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$codebase = $statements_analyzer->getCodebase();
|
||||||
|
|
||||||
if ($assertion_type instanceof TNamedObject
|
if ($assertion_type instanceof TNamedObject
|
||||||
&& strtolower($assertion_type->value) === 'traversable'
|
&& strtolower($assertion_type->value) === 'traversable'
|
||||||
&& isset($existing_var_atomic_types['iterable'])
|
&& isset($existing_var_atomic_types['iterable'])
|
||||||
@ -193,9 +199,21 @@ class NegatedAssertionReconciler extends Reconciler
|
|||||||
) {
|
) {
|
||||||
// checking if two types share a common parent is not enough to guarantee childs are instanceof each other
|
// checking if two types share a common parent is not enough to guarantee childs are instanceof each other
|
||||||
// fall through
|
// fall through
|
||||||
|
} elseif ($existing_var_type->isArray()
|
||||||
|
&& ($assertion->getAtomicType() instanceof TArray
|
||||||
|
|| $assertion->getAtomicType() instanceof TList
|
||||||
|
|| $assertion->getAtomicType() instanceof TKeyedArray)
|
||||||
|
) {
|
||||||
|
//if both types are arrays, try to combine them
|
||||||
|
$combined_type = TypeCombiner::combine(
|
||||||
|
array_merge(array_values($existing_var_type->getAtomicTypes()), [$assertion->getAtomicType()]),
|
||||||
|
$codebase,
|
||||||
|
);
|
||||||
|
$existing_var_type->removeType('array');
|
||||||
|
if ($combined_type->isSingle()) {
|
||||||
|
$existing_var_type->addType($combined_type->getSingleAtomic());
|
||||||
|
}
|
||||||
} elseif (!$is_equality) {
|
} elseif (!$is_equality) {
|
||||||
$codebase = $statements_analyzer->getCodebase();
|
|
||||||
|
|
||||||
$assertion_type = $assertion->getAtomicType();
|
$assertion_type = $assertion->getAtomicType();
|
||||||
|
|
||||||
// if there wasn't a direct hit, go deeper, eliminating subtypes
|
// if there wasn't a direct hit, go deeper, eliminating subtypes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user