Skip to content

Commit 2e145a5

Browse files
authored
Merge branch refs/heads/2.1.x into 2.2.x
2 parents 9712da0 + f70e2bc commit 2e145a5

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/Analyser/MutatingScope.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3956,7 +3956,9 @@ public function mergeWith(?self $otherScope): self
39563956

39573957
$expr = $expressionTypeHolder->getExpr();
39583958

3959-
return $expr instanceof Variable || $expr instanceof VirtualNode;
3959+
return $expr instanceof Variable
3960+
|| $expr instanceof FuncCall
3961+
|| $expr instanceof VirtualNode;
39603962
};
39613963

39623964
$mergedExpressionTypes = array_filter($mergedExpressionTypes, $filter);

tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class NumberComparisonOperatorsConstantConditionRuleTest extends RuleTestCase
1515

1616
private bool $treatPhpDocTypesAsCertain = true;
1717

18+
private bool $polluteScopeWithAlwaysIterableForeach = true;
19+
1820
protected function getRule(): Rule
1921
{
2022
return new NumberComparisonOperatorsConstantConditionRule(
@@ -23,6 +25,11 @@ protected function getRule(): Rule
2325
);
2426
}
2527

28+
protected function shouldPolluteScopeWithAlwaysIterableForeach(): bool
29+
{
30+
return $this->polluteScopeWithAlwaysIterableForeach;
31+
}
32+
2633
public function testBug8277(): void
2734
{
2835
$this->analyse([__DIR__ . '/data/bug-8277.php'], []);
@@ -269,6 +276,12 @@ public function testBug3387(): void
269276
$this->analyse([__DIR__ . '/data/bug-3387.php'], []);
270277
}
271278

279+
public function testBug13984(): void
280+
{
281+
$this->polluteScopeWithAlwaysIterableForeach = false;
282+
$this->analyse([__DIR__ . '/data/bug-13984.php'], []);
283+
}
284+
272285
public function testBug13874(): void
273286
{
274287
$this->analyse([__DIR__ . '/data/bug-13874.php'], []);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace Bug13984;
6+
7+
$list = [
8+
'a',
9+
'b',
10+
'c',
11+
];
12+
13+
/** @param list<string> $list */
14+
function acceptList(array $list): bool {
15+
if (count($list) < 1) {
16+
return false;
17+
}
18+
19+
$compare = ['a', 'b', 'c'];
20+
21+
foreach($list as $key => $item) {
22+
foreach ($compare as $k => $v) {
23+
if ($item === $v && $v !== 'a') {
24+
unset($list[$key]);
25+
}
26+
}
27+
}
28+
29+
if (count($list) > 0) {
30+
return true;
31+
}
32+
33+
return false;
34+
}
35+
36+
assert(acceptList($list) === true);

0 commit comments

Comments
 (0)