Skip to content

Commit

Permalink
Merge pull request #6726 from orklah/crash_intrange
Browse files Browse the repository at this point in the history
Don't crash on falsy with int ranges
  • Loading branch information
orklah authored Oct 24, 2021
2 parents 6852898 + c38139a commit e334923
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ private static function reconcileFalsyOrEmpty(
if ($literal_type->min_bound === null || $literal_type->min_bound <= -1) {
$existing_var_type->addType(new Type\Atomic\TIntRange($literal_type->min_bound, -1));
}
if ($literal_type->min_bound === null || $literal_type->max_bound >= 1) {
if ($literal_type->max_bound === null || $literal_type->max_bound >= 1) {
$existing_var_type->addType(new Type\Atomic\TIntRange(1, $literal_type->max_bound));
}
}
Expand Down
33 changes: 33 additions & 0 deletions tests/IntRangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,39 @@ function getInt(): int{return 0;}
'$k===' => 'int<40, max>',
],
],
'dontCrashOnFalsy' => [
'<?php
function doAnalysis(): void
{
/** @var int<3, max> $shuffle_count */
$shuffle_count = 1;
/** @var list<string> $file_paths */
$file_paths = [];
/** @var int<0, max> $count */
$count = 1;
/** @var int $middle */
$middle = 1;
/** @var int<0, max> $remainder */
$remainder = 1;
for ($i = 0; $i < $shuffle_count; $i++) {
for ($j = 0; $j < $middle; $j++) {
if ($j * $shuffle_count + $i < $count) {
echo $file_paths[$j * $shuffle_count + $i];
}
}
if ($remainder) {
echo $file_paths[$middle * $shuffle_count + $remainder - 1];
$remainder--;
}
}
}',
],
];
}

Expand Down

0 comments on commit e334923

Please sign in to comment.