Skip to content

Commit dcf8b1a

Browse files
ondrejmirtesclaude
andcommitted
Process unrolled foreach iteration body in original context to let nested loops stabilize
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 37ef388 commit dcf8b1a

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/Analyser/NodeScopeResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3986,7 +3986,7 @@ private function tryProcessUnrolledConstantArrayForeach(
39863986
$iterScope,
39873987
$iterStorage,
39883988
new NoopNodeCallback(),
3989-
$context->enterDeep(),
3989+
$context,
39903990
)->filterOutLoopExitPoints();
39913991

39923992
$iterEndScope = $bodyResult->getScope();

tests/PHPStan/Analyser/nsrt/bug-14489.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function () {
2323
}
2424

2525
$values = array_values($cData);
26-
assertType('list{0?: array{1}|array{4}, 1?: array{1}|array{4}}', $values);
26+
assertType('array{array{1}, array{4}}', $values);
2727
};
2828

2929
function () {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug14543;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @return non-empty-list<int>
9+
*/
10+
function getItems(): array
11+
{
12+
return [1, 2, 3];
13+
}
14+
15+
$result = [];
16+
17+
foreach (['a', 'b'] as $key) {
18+
foreach (getItems() as $i) {
19+
$result[] = $i;
20+
}
21+
}
22+
23+
24+
assertType('non-empty-list<int>', $result);

0 commit comments

Comments
 (0)