Skip to content

Commit fbb0018

Browse files
committed
support truethy/falsey
1 parent d02bcc3 commit fbb0018

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,12 +666,12 @@ public function specifyTypesInCondition(
666666

667667
if ($context->true()) {
668668
if (
669-
$scope->getType($expr->left)->isFalse()->yes()
669+
$scope->getType($expr->left)->toBoolean()->isFalse()->yes()
670670
) {
671671
$types = $rightTypes->normalize($rightScope);
672672
} elseif (
673-
$scope->getType($expr->left)->isTrue()->yes()
674-
|| $scope->getType($expr->right)->isFalse()->yes()
673+
$scope->getType($expr->left)->toBoolean()->isTrue()->yes()
674+
|| $scope->getType($expr->right)->toBoolean()->isFalse()->yes()
675675
) {
676676
$types = $leftTypes->normalize($scope);
677677
} else {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ function doFoo(int $i, int $j, $arr): void
1414
assertType('non-empty-array', $arr);
1515
}
1616

17+
if ("0" || array_key_exists($i, $arr)) {
18+
assertType('non-empty-array', $arr);
19+
}
20+
21+
if (array_key_exists($i, $arr) || "0") {
22+
assertType('non-empty-array', $arr);
23+
}
24+
1725
if (true || array_key_exists($i, $arr)) {
1826
assertType('mixed', $arr);
1927
}
@@ -22,6 +30,14 @@ function doFoo(int $i, int $j, $arr): void
2230
assertType('mixed', $arr);
2331
}
2432

33+
if ("1" || array_key_exists($i, $arr)) {
34+
assertType('mixed', $arr);
35+
}
36+
37+
if (array_key_exists($i, $arr) || "1") {
38+
assertType('mixed', $arr);
39+
}
40+
2541
if (array_key_exists($i, $arr) || array_key_exists($j, $arr)) {
2642
assertType('non-empty-array', $arr);
2743
}

0 commit comments

Comments
 (0)