diff --git a/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php b/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php index 1a236bf47..fd0b135b5 100644 --- a/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php +++ b/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php @@ -2,6 +2,7 @@ namespace Psalm\Internal\Type; +use Iterator; use Psalm\Codebase; use Psalm\Internal\Analyzer\StatementsAnalyzer; use Psalm\Internal\Type\Comparator\CallableTypeComparator; @@ -12,6 +13,7 @@ use Psalm\Type\Union; use function array_merge; use function array_values; use function count; +use function in_array; use function is_a; use function reset; use function strpos; @@ -469,6 +471,13 @@ class TemplateStandinTypeReplacer $matching_atomic_types[$atomic_input_type->getId()] = $atomic_input_type; continue; } + + if (in_array('Traversable', $classlike_storage->class_implements) + && $base_type->value === 'Iterator' + ) { + $matching_atomic_types[$atomic_input_type->getId()] = $atomic_input_type; + continue; + } } catch (\InvalidArgumentException $e) { // do nothing } @@ -487,12 +496,6 @@ class TemplateStandinTypeReplacer ); continue; } - - /** @var class-string $key may not always be true but class_exists on built in classes(Iterator) is wrong */ - if (is_a($input_key, $key, true)) { - $matching_atomic_types[$atomic_input_type->getId()] = $atomic_input_type; - continue; - } } return array_values($matching_atomic_types);