1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 12:24:49 +01:00

Fix undefined array offset when too few iterator params supplied

This commit is contained in:
Matthew Brown 2019-10-21 07:13:27 -04:00
parent 94636476d2
commit 233977a764
3 changed files with 13 additions and 2 deletions

View File

@ -11,7 +11,7 @@
throwExceptionOnError="0"
findUnusedCode="true"
ensureArrayStringOffsetsExist="true"
ensureArrayIntOffsetsExist="false"
ensureArrayIntOffsetsExist="true"
resolveFromConfigFile="true"
xsi:schemaLocation="https://getpsalm.org/schema/config config.xsd"
>

View File

@ -997,7 +997,7 @@ class ForeachAnalyzer
if (isset($class_template_types[$template_name]) && $calling_type_params) {
$offset = array_search($template_name, array_keys($class_template_types));
if ($offset !== false) {
if ($offset !== false && isset($calling_type_params[$offset])) {
return $calling_type_params[$offset];
}
}

View File

@ -969,6 +969,17 @@ class ForeachTest extends \Psalm\Tests\TestCase
}
}'
],
'loopOverIteratorWithTooFewParams' => [
'<?php
/**
* @param Iterator<string> $arr
* @psalm-suppress MissingTemplateParam
* @psalm-suppress MixedAssignment
*/
function foo(Iterator $arr) : void {
foreach ($arr as $a) {}
}'
],
];
}