Skip to content
Permalink
Browse files

Fix possible issue negating falsy assertion

  • Loading branch information...
muglug committed Aug 18, 2019
1 parent 43a9ff0 commit 9d62971006e47ac99274ed9e76bef2af580bbdba
Showing with 19 additions and 1 deletion.
  1. +6 −1 src/Psalm/Type/Reconciler.php
  2. +13 −0 tests/Loop/WhileTest.php
@@ -184,6 +184,7 @@ public static function reconcileKeyedTypes(
$has_equality = false;
$has_isset = false;
$has_not_isset = false;
$has_falsyish = false;
$has_count_check = false;
foreach ($new_type_parts as $new_type_part_parts) {
@@ -204,6 +205,10 @@ public static function reconcileKeyedTypes(
|| $new_type_part_part === '=isset'
|| $new_type_part_part === 'array-key-exists';
$has_falsyish = $has_falsyish
|| $new_type_part_part === 'empty'
|| $new_type_part_part === 'falsy';
$has_not_isset = $has_not_isset || $new_type_part_part === '!isset';
$has_count_check = $has_count_check
@@ -289,7 +294,7 @@ function (array $new_type_part_parts) {
$code_location,
$suppressed_issues
);
} elseif (!$has_negation && !$has_isset) {
} elseif (!$has_negation && !$has_falsyish && !$has_isset) {
$changed_var_ids[] = $key;
}
@@ -328,6 +328,19 @@ function foo(Obj $node) : void {
while (--$i > 0) {}
echo $i === 0;',
],
'noRedundantConditionOnAddedSubtractedInLoop' => [
'<?php
$depth = 0;
$position = 0;
while (!$depth) {
if (rand(0, 1)) {
$depth++;
} elseif (rand(0, 1)) {
$depth--;
}
$position++;
}'
],
];
}

0 comments on commit 9d62971

Please sign in to comment.
You can’t perform that action at this time.