diff --git a/psalm.xml.dist b/psalm.xml.dist index e549a1511..5d08ce7f7 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -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" > diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php index e96d92485..564924edf 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php @@ -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]; } } diff --git a/tests/Loop/ForeachTest.php b/tests/Loop/ForeachTest.php index d7d43021a..1edb61101 100644 --- a/tests/Loop/ForeachTest.php +++ b/tests/Loop/ForeachTest.php @@ -969,6 +969,17 @@ class ForeachTest extends \Psalm\Tests\TestCase } }' ], + 'loopOverIteratorWithTooFewParams' => [ + ' $arr + * @psalm-suppress MissingTemplateParam + * @psalm-suppress MixedAssignment + */ + function foo(Iterator $arr) : void { + foreach ($arr as $a) {} + }' + ], ]; }