Skip to content

Commit fa86019

Browse files
authored
Merge branch refs/heads/2.1.x into 2.2.x
2 parents e5e64c7 + 3993c52 commit fa86019

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/Analyser/MutatingScope.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4103,6 +4103,12 @@ private function createConditionalExpressions(
41034103
if ($mergedExpressionTypes[$exprString]->equalTypes($holder)) {
41044104
continue;
41054105
}
4106+
if (
4107+
array_key_exists($exprString, $theirExpressionTypes)
4108+
&& !$theirExpressionTypes[$exprString]->getCertainty()->yes()
4109+
) {
4110+
continue;
4111+
}
41064112

41074113
$typeGuards[$exprString] = $holder;
41084114
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ConditionalHoldersOrAssertIsset;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @return list<int>
9+
*/
10+
function getListOfIds(): array {
11+
return [3];
12+
}
13+
14+
/**
15+
* @phpstan-impure
16+
*/
17+
function getBool(): bool {
18+
return (bool) rand(0, 1);
19+
}
20+
21+
$displayDetails = getBool();
22+
$displayList = getBool();
23+
24+
if ($displayList || $displayDetails) {
25+
$listOfIds = getListOfIds();
26+
}
27+
28+
if ($displayList) {
29+
assert(isset($listOfIds));
30+
}
31+
32+
if ($displayDetails) {
33+
assert(isset($listOfIds));
34+
assertType('bool', $displayList);
35+
}

0 commit comments

Comments
 (0)