mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix #606 - fatal error when evaluating array_key_exists
This commit is contained in:
parent
8ce46aabd2
commit
8dcb878af4
@ -894,7 +894,11 @@ class AssertionFinder
|
||||
}
|
||||
}
|
||||
|
||||
if ($first_var_name !== null && $array_root && !strpos($first_var_name, '->')) {
|
||||
if ($first_var_name !== null
|
||||
&& $array_root
|
||||
&& !strpos($first_var_name, '->')
|
||||
&& !strpos($first_var_name, '[')
|
||||
) {
|
||||
$if_types[$array_root . '[' . $first_var_name . ']'] = $prefix . 'array-key-exists';
|
||||
}
|
||||
}
|
||||
|
@ -862,6 +862,38 @@ class ArrayAssignmentTest extends TestCase
|
||||
echo $a[0];
|
||||
}',
|
||||
],
|
||||
'noCrashOnArrayKeyExistsBracket' => [
|
||||
'<?php
|
||||
class MyCollection {
|
||||
/**
|
||||
* @param int $commenter
|
||||
* @param int $numToGet
|
||||
* @return int[]
|
||||
*/
|
||||
public function getPosters($commenter, $numToGet=10) {
|
||||
$posters = array();
|
||||
$count = 0;
|
||||
$a = new ArrayObject([[1234]]);
|
||||
$iter = $a->getIterator();
|
||||
while ($iter->valid() && $count < $numToGet) {
|
||||
$value = $iter->current();
|
||||
if ($value[0] != $commenter) {
|
||||
if (!array_key_exists($value[0], $posters)) {
|
||||
$posters[$value[0]] = 1;
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
$iter->next();
|
||||
}
|
||||
return array_keys($posters);
|
||||
}
|
||||
}',
|
||||
'assertions' => [],
|
||||
'error_levels' => [
|
||||
'MixedArrayAccess', 'MixedAssignment', 'MixedArrayOffset',
|
||||
'MixedArgument', 'LessSpecificReturnStatement', 'MoreSpecificReturnType',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user