Skip to content

Commit

Permalink
fix reconciliation between a list and iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
orklah committed Jun 22, 2023
1 parent 2e8d575 commit 8929f8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Psalm/Internal/Type/AssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -771,12 +771,25 @@ private static function filterAtomicWithAnother(
}

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);

$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;
}

Expand Down
1 change: 1 addition & 0 deletions tests/TypeReconciliation/ReconcilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public function providerTestReconcilation(): array
'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'],
'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>'],
];
}

Expand Down

0 comments on commit 8929f8b

Please sign in to comment.