diff --git a/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php index e8c344716c8..9ee13a6389b 100644 --- a/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php @@ -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)); } } diff --git a/tests/IntRangeTest.php b/tests/IntRangeTest.php index 2ca86eb5f66..b6b5919b9c1 100644 --- a/tests/IntRangeTest.php +++ b/tests/IntRangeTest.php @@ -608,6 +608,39 @@ function getInt(): int{return 0;} '$k===' => 'int<40, max>', ], ], + 'dontCrashOnFalsy' => [ + ' $shuffle_count */ + $shuffle_count = 1; + + /** @var list $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--; + } + } + }', + ], ]; }