Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion stubs/iterable.stub
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class RegexIterator extends FilterIterator {
const USE_KEY = 1 ;

/**
* @param Iterator<TKey, TValue> $iterator
* @param TIterator $iterator
* @param self::MATCH|self::GET_MATCH|self::ALL_MATCHES|self::SPLIT|self::REPLACE $mode
*/
public function __construct(Iterator $iterator, string $regex, int $mode = self::MATCH, int $flags = 0, int $preg_flags = 0) {}
Expand Down
25 changes: 25 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-13325.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Bug13325Nsrt;

use function PHPStan\Testing\assertType;

class Foo
{

/**
* @param \Iterator<int, string> $iterator
*/
public function doFoo(\Iterator $iterator): void
{
$regexIterator = new \RegexIterator($iterator, '/pattern/');
assertType('RegexIterator<int, string, Iterator<int, string>>', $regexIterator);
}

public function doBar(): void
{
$regexIterator = new \RegexIterator(new \FilesystemIterator('foo'), '/pattern/');
assertType('RegexIterator<mixed, mixed, FilesystemIterator>', $regexIterator);
}

}
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'], []);
}

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

declare(strict_types=1);

namespace Bug13325;

use FilesystemIterator;
use Iterator;
use RegexIterator;

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

/** @return RegexIterator<mixed, mixed, FilesystemIterator> */
public function createRegionIterator(): RegexIterator
{
return new RegexIterator(
new FilesystemIterator('foo'),
'/bar/',
);
}
}
Loading