Skip to content

Commit c503d10

Browse files
committed
Merge branch 2.1.x into 2.2.x
2 parents 0966bb8 + 2d99669 commit c503d10

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1939,9 +1939,15 @@ private function processBooleanSureConditionalTypes(Scope $scope, SpecifiedTypes
19391939
continue;
19401940
}
19411941

1942+
$scopeType = $scope->getType($expr);
1943+
$conditionType = TypeCombinator::remove($scopeType, $type);
1944+
if ($scopeType->equals($conditionType)) {
1945+
continue;
1946+
}
1947+
19421948
$conditionExpressionTypes[$exprString] = ExpressionTypeHolder::createYes(
19431949
$expr,
1944-
TypeCombinator::remove($scope->getType($expr), $type),
1950+
$conditionType,
19451951
);
19461952
}
19471953

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace BugPr5445;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @param array<string, mixed> $aggregation
9+
* @param non-falsy-string $type
10+
*/
11+
function testTriviallyTrueConditionSkipped(array $aggregation, string $type): void
12+
{
13+
if (empty($aggregation['field']) && $type !== 'filter') {
14+
return;
15+
}
16+
17+
assertType("array<string, mixed>", $aggregation);
18+
assertType('non-falsy-string', $type);
19+
20+
if ($type !== 'filter') {
21+
assertType("array<string, mixed>", $aggregation);
22+
}
23+
24+
assertType('non-falsy-string', $type);
25+
}

0 commit comments

Comments
 (0)