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:
parent
13824d5a33
commit
457abc6e13
@ -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);
|
||||
|
@ -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;
|
||||
}'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user