1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Don’t erase already-known literal ints

Fixes #4644
This commit is contained in:
Matt Brown 2020-11-21 18:26:13 -05:00 committed by Daniil Gentili
parent 48fba8a6b9
commit 48a58c56e3
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 15 additions and 2 deletions

View File

@ -1219,7 +1219,7 @@ class TypeCombiner
}
if ($combination->ints !== null && count($combination->ints) < $literal_limit) {
$combination->ints[$type_key] = $type;
$combination->ints[(string) $type_key] = $type;
} else {
$combination->ints[$type_key] = $type;
@ -1269,7 +1269,12 @@ class TypeCombiner
&& isset($combination->value_types['int'])
&& $combination->value_types['int'] instanceof TPositiveInt
) {
$combination->ints = ['int(0)' => new TLiteralInt(0)];
if ($combination->ints === null) {
$combination->ints = ['int(0)' => new TLiteralInt(0)];
} elseif ($type->value < 0) {
$combination->ints = null;
$combination->value_types['int'] = new TInt();
}
}
return null;

View File

@ -591,6 +591,14 @@ class TypeCombinationTest extends TestCase
'-1',
],
],
'combinePositiveIntZeroAndMinusOne' => [
'int',
[
'0',
'positive-int',
'-1',
],
],
'combineMinusOneAndPositiveInt' => [
'int',
[