Skip to content

Commit

Permalink
Fix #5198 - allow is_array check on templated
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Feb 12, 2021
1 parent c9ff1ee commit fa33737
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Type/SimpleAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ private static function reconcileArray(

$did_remove_type = true;
} elseif ($type instanceof TTemplateParam) {
if ($type->as->hasArray() || $type->as->hasMixed()) {
if ($type->as->hasArray() || $type->as->hasIterable() || $type->as->hasMixed()) {
$type = clone $type;

$type->as = self::reconcileArray(
Expand Down
5 changes: 5 additions & 0 deletions src/Psalm/Type/Union.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,11 @@ public function hasArray(): bool
return isset($this->types['array']);
}

public function hasIterable(): bool
{
return isset($this->types['iterable']);
}

public function hasList(): bool
{
return isset($this->types['array']) && $this->types['array'] instanceof Atomic\TList;
Expand Down
11 changes: 11 additions & 0 deletions tests/Template/FunctionTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,17 @@ public function get($default)
}
}'
],
'isArrayCheckOnTemplated' => [
'<?php
/**
* @psalm-pure
* @template TIterable of iterable
*/
function toList(iterable $iterable): void
{
if (is_array($iterable)) {}
}'
],
];
}

Expand Down

0 comments on commit fa33737

Please sign in to comment.