1
0
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:
orklah 2022-01-15 23:27:22 +01:00 committed by GitHub
commit 32c8e6358c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -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();
}

View File

@ -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>>',
],
],
];
}