Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Analyser/Traverser/GenericTypeTemplateTraverser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function traverse(Type $type, callable $traverse): Type
if ($type instanceof TemplateType && !$type->isArgument()) {
$newType = $this->resolvedTemplateTypeMap->getType($type->getName());
if ($newType === null || $newType instanceof ErrorType) {
return $type->getDefault() ?? $type->getBound();
return $traverse($type->getDefault() ?? $type->getBound());
}

return TemplateTypeHelper::generalizeInferredTemplateType($type, $newType);
Expand Down
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1326,4 +1326,9 @@ public function testBug10924(): void
$this->analyse([__DIR__ . '/data/bug-10924.php'], []);
}

public function testBug13325(): void
{
$this->analyse([__DIR__ . '/data/bug-13325.php'], []);
}

}
18 changes: 18 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-13325.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Bug13325;

use Iterator;
use RegexIterator;
use Traversable;

final class Foo
{
/** @return RegexIterator<mixed, mixed, Traversable<mixed, mixed>> */
public function __invoke(Iterator $iterator): RegexIterator
{
return new RegexIterator($iterator, 'string');
}
}
Loading