1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Merge pull request #9950 from orklah/iterableInt

fix reconciliation between a list and iterable
This commit is contained in:
orklah 2023-06-22 23:45:39 +02:00 committed by GitHub
commit 01e2ac78d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -771,12 +771,25 @@ class AssertionReconciler extends Reconciler
} }
if ($type_1_param->getId() !== $type_2_param->getId()) { if ($type_1_param->getId() !== $type_2_param->getId()) {
$type_1_param = $type_2_param; $type_1_param = $type_2_param->setPossiblyUndefined($type_1_param->possibly_undefined);
} }
} }
unset($type_1_param); unset($type_1_param);
$matching_atomic_type = $type_1_atomic->setProperties($type_1_properties); if ($type_1_atomic->fallback_params === null) {
$fallback_types = null;
} else {
//any fallback type is now the value of iterable
$fallback_types = [$type_1_atomic->fallback_params[0], $type_2_param];
}
$matching_atomic_type = new TKeyedArray(
$type_1_properties,
$type_1_atomic->class_strings,
$fallback_types,
$type_1_atomic->is_list,
$type_1_atomic->from_docblock,
);
$atomic_comparison_results->type_coerced = true; $atomic_comparison_results->type_coerced = true;
} }

View File

@ -179,6 +179,7 @@ class ReconcilerTest extends TestCase
'IsNotAClassReconciliation' => ['int', new Assertion\IsNotAClass(new TNamedObject('IDObject'), true), 'int|IDObject'], 'IsNotAClassReconciliation' => ['int', new Assertion\IsNotAClass(new TNamedObject('IDObject'), true), 'int|IDObject'],
'nonEmptyArray' => ['non-empty-array<array-key, mixed>', new IsType(Atomic::create('non-empty-array')), 'array'], 'nonEmptyArray' => ['non-empty-array<array-key, mixed>', new IsType(Atomic::create('non-empty-array')), 'array'],
'nonEmptyList' => ['non-empty-list<mixed>', new IsType(Atomic::create('non-empty-list')), 'array'], 'nonEmptyList' => ['non-empty-list<mixed>', new IsType(Atomic::create('non-empty-list')), 'array'],
'ListOfInts' => ['list<int>', new IsType(new TIterable([Type::getMixed(), Type::getInt()])), 'list<mixed>'],
]; ];
} }