Skip to content
Permalink
Browse files

Fix removal of traversable from iterable

Fixes #2509
  • Loading branch information
muglug committed Dec 27, 2019
1 parent 068afa0 commit 4a28525275829539f3a70b87fcb044e4c431028e
@@ -238,13 +238,15 @@ public static function reconcile(
}

if (strtolower($assertion) === 'traversable'
&& isset($existing_var_type->getTypes()['iterable'])
&& isset($existing_var_atomic_types['iterable'])
) {
/** @var Type\Atomic\TIterable */
$iterable = $existing_var_atomic_types['iterable'];
$existing_var_type->removeType('iterable');
$existing_var_type->addType(new TArray(
[
new Type\Union([new TArrayKey]),
new Type\Union([new TMixed]),
$iterable->type_params[0],
$iterable->type_params[1],
]
));
} elseif (strtolower($assertion) === 'int'
@@ -2376,6 +2376,20 @@ function test(): string {
return $foo;
}'
],
'isNotTraversable' => [
'<?php
/**
* @psalm-param iterable<string> $collection
* @psalm-return array<string>
*/
function order(iterable $collection): array {
if ($collection instanceof \Traversable) {
$collection = iterator_to_array($collection, false);
}
return $collection;
}'
],
];
}

0 comments on commit 4a28525

Please sign in to comment.
You can’t perform that action at this time.