Skip to content

Commit

Permalink
Merge pull request #6390 from orklah/templateGenerator
Browse files Browse the repository at this point in the history
fix Generator giving templates to Iterator
  • Loading branch information
weirdan committed Sep 2, 2021
2 parents eb973ab + 854858a commit 4b3d02f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php
Expand Up @@ -12,6 +12,7 @@
use function array_merge;
use function array_values;
use function count;
use function is_a;
use function reset;
use function strpos;
use function substr;
Expand Down Expand Up @@ -483,6 +484,12 @@ private static function findMatchingAtomicTypesForTemplate(
$atomic_input_type->as
)
);
continue;
}

if (is_a($input_key, $key, true)) {
$matching_atomic_types[$atomic_input_type->getId()] = $atomic_input_type;
continue;
}
}

Expand Down
16 changes: 16 additions & 0 deletions tests/GeneratorTest.php
Expand Up @@ -270,6 +270,22 @@ function f() : Generator {
[],
['UndefinedClass']
],
'fillTemplatesForIteratorFromGenerator' => [
'<?php
/**
* @return Generator<int, string>
*/
function generator(): Generator
{
yield "test";
}
$iterator = new NoRewindIterator(generator());
',
'assertions' => [
'$iterator' => 'NoRewindIterator<int, string>',
]
],
];
}

Expand Down

0 comments on commit 4b3d02f

Please sign in to comment.