Skip to content

Commit edb776f

Browse files
authored
Merge branch refs/heads/2.1.x into 2.2.x
2 parents 19b0f0b + 676555f commit edb776f

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

src/Analyser/MutatingScope.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3805,16 +3805,23 @@ public function filterBySpecifiedTypes(SpecifiedTypes $specifiedTypes): self
38053805
}
38063806

38073807
$conditions = [];
3808-
foreach ($scope->conditionalExpressions as $conditionalExprString => $conditionalExpressions) {
3809-
foreach ($conditionalExpressions as $conditionalExpression) {
3810-
foreach ($conditionalExpression->getConditionExpressionTypeHolders() as $holderExprString => $conditionalTypeHolder) {
3811-
if (!array_key_exists($holderExprString, $specifiedExpressions) || !$specifiedExpressions[$holderExprString]->equals($conditionalTypeHolder)) {
3812-
continue 2;
3813-
}
3808+
$prevSpecifiedCount = -1;
3809+
while (count($specifiedExpressions) !== $prevSpecifiedCount) {
3810+
$prevSpecifiedCount = count($specifiedExpressions);
3811+
foreach ($scope->conditionalExpressions as $conditionalExprString => $conditionalExpressions) {
3812+
if (array_key_exists($conditionalExprString, $conditions)) {
3813+
continue;
38143814
}
3815+
foreach ($conditionalExpressions as $conditionalExpression) {
3816+
foreach ($conditionalExpression->getConditionExpressionTypeHolders() as $holderExprString => $conditionalTypeHolder) {
3817+
if (!array_key_exists($holderExprString, $specifiedExpressions) || !$specifiedExpressions[$holderExprString]->equals($conditionalTypeHolder)) {
3818+
continue 2;
3819+
}
3820+
}
38153821

3816-
$conditions[$conditionalExprString][] = $conditionalExpression;
3817-
$specifiedExpressions[$conditionalExprString] = $conditionalExpression->getTypeHolder();
3822+
$conditions[$conditionalExprString][] = $conditionalExpression;
3823+
$specifiedExpressions[$conditionalExprString] = $conditionalExpression->getTypeHolder();
3824+
}
38183825
}
38193826
}
38203827

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug14178;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class HelloWorld {
8+
/**
9+
* @return list<string>
10+
*/
11+
public static function diff(
12+
?self $previousVersion,
13+
?self $newVersion,
14+
): array {
15+
$previousVersionExists = $previousVersion !== null;
16+
$newVersionExists = $newVersion !== null;
17+
18+
if (!$previousVersionExists && !$newVersionExists) {
19+
return [];
20+
}
21+
22+
if ($previousVersionExists && !$newVersionExists) {
23+
return ['bar'];
24+
}
25+
26+
if (!$previousVersionExists) {
27+
assertType('true', $newVersionExists);
28+
assertType('Bug14178\\HelloWorld', $newVersion);
29+
$result = [];
30+
$result[] = 'foo';
31+
$categoryString = implode(', ', $newVersion->getSomething());
32+
}
33+
34+
return [];
35+
}
36+
37+
/**
38+
* @return array<string>
39+
*/
40+
private function getSomething(): array {
41+
return ['foo'];
42+
}
43+
}

tests/PHPStan/Analyser/nsrt/dependent-expression-certainty.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function (bool $a, bool $b) {
153153

154154
assertVariableCertainty(TrinaryLogic::createMaybe(), $foo);
155155
if (returnsBool($b)) {
156-
assertVariableCertainty(TrinaryLogic::createMaybe(), $foo); // could be Yes
156+
assertVariableCertainty(TrinaryLogic::createYes(), $foo);
157157
}
158158

159159
if (returnsBool($a)) {

tests/PHPStan/Analyser/nsrt/dependent-variable-certainty.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function (bool $a, bool $b) {
149149

150150
assertVariableCertainty(TrinaryLogic::createMaybe(), $foo);
151151
if ($b) {
152-
assertVariableCertainty(TrinaryLogic::createMaybe(), $foo); // could be Yes
152+
assertVariableCertainty(TrinaryLogic::createYes(), $foo);
153153
}
154154

155155
if ($a) {

0 commit comments

Comments
 (0)