diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index dd38f798f2..5090d04402 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -3986,7 +3986,7 @@ private function tryProcessUnrolledConstantArrayForeach( $iterScope, $iterStorage, new NoopNodeCallback(), - $context->enterDeep(), + $context, )->filterOutLoopExitPoints(); $iterEndScope = $bodyResult->getScope(); diff --git a/tests/PHPStan/Analyser/nsrt/bug-14489.php b/tests/PHPStan/Analyser/nsrt/bug-14489.php index 53c374b039..f1471e754a 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-14489.php +++ b/tests/PHPStan/Analyser/nsrt/bug-14489.php @@ -23,7 +23,7 @@ function () { } $values = array_values($cData); - assertType('list{0?: array{1}|array{4}, 1?: array{1}|array{4}}', $values); + assertType('array{array{1}, array{4}}', $values); }; function () { diff --git a/tests/PHPStan/Analyser/nsrt/bug-14543.php b/tests/PHPStan/Analyser/nsrt/bug-14543.php new file mode 100644 index 0000000000..05a783e015 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-14543.php @@ -0,0 +1,24 @@ + + */ +function getItems(): array +{ + return [1, 2, 3]; +} + +$result = []; + +foreach (['a', 'b'] as $key) { + foreach (getItems() as $i) { + $result[] = $i; + } +} + + +assertType('non-empty-list', $result); diff --git a/tests/PHPStan/Analyser/nsrt/bug-9332.php b/tests/PHPStan/Analyser/nsrt/bug-9332.php new file mode 100644 index 0000000000..d774abc48c --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-9332.php @@ -0,0 +1,29 @@ + 'asdfghi']; + foreach (['b', 'c'] as $x) { + foreach (['d', 'e'] as $y) { + $data[$x . $y] = mt_rand(1, 1000); + } + } + + assertType("array{a: 'asdfghi', bd: int<1, 1000>, be: int<1, 1000>, cd: int<1, 1000>, ce: int<1, 1000>}", $data); + $this->doSomething($data); + } + + /** + * @param array{a: string, bd: int, be: int, cd: int, ce: int} $a + */ + private function doSomething(array $a): void + { + + } +}