Skip to content

Commit

Permalink
Fix reconciliation of mixed to Traversable
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Aug 18, 2019
1 parent 1b983ba commit b8bdaea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Type/AssertionReconciler.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ private static function reconcileTraversable(
$existing_var_atomic_types = $existing_var_type->getTypes(); $existing_var_atomic_types = $existing_var_type->getTypes();


if ($existing_var_type->hasMixed() || $existing_var_type->hasTemplate()) { if ($existing_var_type->hasMixed() || $existing_var_type->hasTemplate()) {
return new Type\Union([new Type\Atomic\TIterable]); return new Type\Union([new Type\Atomic\TNamedObject('Traversable')]);
} }


$traversable_types = []; $traversable_types = [];
Expand Down
10 changes: 10 additions & 0 deletions tests/TypeReconciliationTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1458,6 +1458,16 @@ function getBar(SimpleXMLElement $e, string $s) : void {
if (isset($e->bar)) {} if (isset($e->bar)) {}
}', }',
], ],
'assertArrayOffsetToTraversable' => [
'<?php
function render(array $data): ?Traversable {
if ($data["o"] instanceof Traversable) {
return $data["o"];
}
return null;
}'
],
]; ];
} }


Expand Down

0 comments on commit b8bdaea

Please sign in to comment.