1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Don’t subtract int from array-key if not equality

This commit is contained in:
Matthew Brown 2022-02-08 11:24:05 -05:00
parent 13824d5a33
commit 457abc6e13
2 changed files with 15 additions and 0 deletions

View File

@ -181,6 +181,7 @@ class NegatedAssertionReconciler extends Reconciler
));
} elseif ($assertion_type instanceof TInt
&& isset($existing_var_type->getAtomicTypes()['array-key'])
&& !$is_equality
) {
$existing_var_type->removeType('array-key');
$existing_var_type->addType(new TString);

View File

@ -800,6 +800,20 @@ class IntRangeTest extends TestCase
],
],
'arraykeyCanBeRange' => [
'code' => '<?php
/**
* @param array-key $key
* @param positive-int $expected
*/
function matches($key, int $expected): bool {
if ($key !== $expected) {
return false;
}
return true;
}'
]
];
}