mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Fix undefined array offset when too few iterator params supplied
This commit is contained in:
parent
94636476d2
commit
233977a764
@ -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"
|
||||
>
|
||||
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
@ -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) {}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user