Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CachingIterator::getCache stub. #1519

Merged
merged 2 commits into from Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions stubs/iterable.stub
Expand Up @@ -403,6 +403,11 @@ class CachingIterator extends IteratorIterator implements OuterIterator, ArrayAc
* @return TKey
*/
public function key() {}

/**
* @return array<array-key, TValue>
*/
public function getCache() {}
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Expand Up @@ -927,6 +927,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7580.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/this-subtractable.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/match-expression-inference.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-1519.php');
}

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/PHPStan/Analyser/data/bug-1519.php
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App;

use Generator;
use CachingIterator;
use function PHPStan\Testing\assertType;

$generator =
/**
* @return Generator<bool, bool>
*/
static function (): Generator {
yield true => true;
yield false => false;
};

$iterator = new CachingIterator($generator(), CachingIterator::FULL_CACHE);
$cache = $iterator->getCache();
assertType('array<bool>', $cache);