Skip to content

Commit

Permalink
Maintain loop start value after an increment
Browse files Browse the repository at this point in the history
  • Loading branch information
robchett committed Oct 8, 2023
1 parent 69d5881 commit 1dd2a78
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,9 @@ private static function analyzeOperands(
}
}
} else {
$start = $left_type_part instanceof TLiteralInt ? $left_type_part->value : 1;
$result_type = Type::combineUnionTypes(
$always_positive ? Type::getIntRange(1, null) : Type::getInt(true),
$always_positive ? Type::getIntRange($start, null) : Type::getInt(true),
$result_type,
);
}
Expand Down
17 changes: 17 additions & 0 deletions tests/BinaryOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,23 @@ function scope(array $a): int|float {
'$b' => 'float|int',
],
],
'incrementInLoop' => [
'code' => '<?php
for ($i = 0; $i < 10; $i++) {
if (rand(0,1)) {
break;
}
}
for ($j = 100; $j < 110; $j++) {
if (rand(0,1)) {
break;
}
}',
'assertions' => [
'$i' => 'int<0, 10>',
'$j' => 'int<100, 110>',
],
],
'coalesceFilterOutNullEvenWithTernary' => [
'code' => '<?php
Expand Down

0 comments on commit 1dd2a78

Please sign in to comment.