mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
144bb37f76
When checking code like the following: ``` <?php function checkNegated(string $key): void { $arr = [ 0 => "foo", 1 => "bar", ]; if (!array_key_exists($key, $arr)) { printf("not found\n"); } } function check(string $key): void { $arr = [ 0 => "foo", 1 => "bar", ]; if (array_key_exists($key, $arr)) { printf("found\n"); } } ``` the `if` in `checkNegated` would cause: ``` ERROR: RedundantCondition - 9:10 - Type string for $key is never =int(0) ``` This happens when the array keys are all int literals, but the "needle" is a string. `array_key_exists()` uses a loose equality comparison, but the generated assertions for this specific case (`AssertionFinder::getArrayKeyExistsAssertions`) was generating strict equality clauses. This commit fixes it by changing the generated clause from `=` to `~`. |
||
---|---|---|
.. | ||
ArrayKeyExistsTest.php | ||
AssignmentInConditionalTest.php | ||
ConditionalTest.php | ||
EmptyTest.php | ||
IssetTest.php | ||
ReconcilerTest.php | ||
RedundantConditionTest.php | ||
ScopeTest.php | ||
TypeAlgebraTest.php | ||
TypeTest.php | ||
ValueTest.php |