mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Merge pull request #7400 from orklah/combinePositiveAndRange
Combine positive int and range
This commit is contained in:
commit
32c8e6358c
@ -1181,6 +1181,13 @@ class TypeCombiner
|
||||
}
|
||||
} 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();
|
||||
}
|
||||
|
@ -684,6 +684,19 @@ class IntRangeTest extends TestCase
|
||||
'$length===' => '1',
|
||||
],
|
||||
],
|
||||
'PositiveIntCombinedWithIntRange' => [
|
||||
'<?php
|
||||
/** @var positive-int */
|
||||
$int = 1;
|
||||
/** @var array<int<0, max>, int<0, max>> */
|
||||
$_arr = [];
|
||||
|
||||
$_arr[1] = $int;
|
||||
$_arr[$int] = 2;',
|
||||
'assertions' => [
|
||||
'$_arr===' => 'non-empty-array<int<0, max>, int<0, max>>',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user