mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fix possible issue negating falsy assertion
This commit is contained in:
parent
43a9ff0735
commit
9d62971006
@ -184,6 +184,7 @@ class Reconciler
|
||||
$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 @@ class Reconciler
|
||||
|| $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 @@ class Reconciler
|
||||
$code_location,
|
||||
$suppressed_issues
|
||||
);
|
||||
} elseif (!$has_negation && !$has_isset) {
|
||||
} elseif (!$has_negation && !$has_falsyish && !$has_isset) {
|
||||
$changed_var_ids[] = $key;
|
||||
}
|
||||
|
||||
|
@ -328,6 +328,19 @@ class WhileTest extends \Psalm\Tests\TestCase
|
||||
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++;
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user