From f48def6d510a0a9b66aa8ae1a7f63d6759d55811 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Mon, 18 Jul 2022 16:47:47 +0200 Subject: [PATCH 1/2] Update `CachingIterator::getCache` stub. --- stubs/iterable.stub | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stubs/iterable.stub b/stubs/iterable.stub index 2e10bf3889..5cefe2f196 100644 --- a/stubs/iterable.stub +++ b/stubs/iterable.stub @@ -403,6 +403,11 @@ class CachingIterator extends IteratorIterator implements OuterIterator, ArrayAc * @return TKey */ public function key() {} + + /** + * @return array + */ + public function getCache() {} } /** From 60561a80dbecd83168d580786b41c176b9a44036 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Mon, 18 Jul 2022 17:58:50 +0200 Subject: [PATCH 2/2] Add test. --- .../Analyser/NodeScopeResolverTest.php | 1 + tests/PHPStan/Analyser/data/bug-1519.php | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/PHPStan/Analyser/data/bug-1519.php diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 122089b4d4..889acc4b7b 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -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'); } /** diff --git a/tests/PHPStan/Analyser/data/bug-1519.php b/tests/PHPStan/Analyser/data/bug-1519.php new file mode 100644 index 0000000000..7d01391c63 --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-1519.php @@ -0,0 +1,22 @@ + + */ + static function (): Generator { + yield true => true; + yield false => false; + }; + +$iterator = new CachingIterator($generator(), CachingIterator::FULL_CACHE); +$cache = $iterator->getCache(); +assertType('array', $cache);