diff --git a/src/Psalm/Internal/Type/TypeCombiner.php b/src/Psalm/Internal/Type/TypeCombiner.php index 99fbeffff30..9e7579c3d3e 100644 --- a/src/Psalm/Internal/Type/TypeCombiner.php +++ b/src/Psalm/Internal/Type/TypeCombiner.php @@ -1181,6 +1181,13 @@ function ($int): bool { } } elseif (!isset($combination->value_types['int'])) { $combination->value_types['int'] = $type; + } elseif ($combination->value_types['int'] instanceof TIntRange) { + //if we already had a range, we ensure the min is no higher than 1 + $combination->value_types['int']->min_bound = TIntRange::getNewLowestBound( + $combination->value_types['int']->min_bound, + 1 + ); + $combination->value_types['int']->max_bound = null; } elseif (get_class($combination->value_types['int']) !== get_class($type)) { $combination->value_types['int'] = new TInt(); } diff --git a/tests/IntRangeTest.php b/tests/IntRangeTest.php index 60d799af2b9..33cb1339b35 100644 --- a/tests/IntRangeTest.php +++ b/tests/IntRangeTest.php @@ -684,6 +684,19 @@ function doAnalysis(): void '$length===' => '1', ], ], + 'PositiveIntCombinedWithIntRange' => [ + ', int<0, max>> */ + $_arr = []; + + $_arr[1] = $int; + $_arr[$int] = 2;', + 'assertions' => [ + '$_arr===' => 'non-empty-array, int<0, max>>', + ], + ], ]; }