Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix reconciliation between a list and iterable #9950

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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