1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #3625 - getIterator call is used inside loop

This commit is contained in:
Matt Brown 2020-10-20 10:59:09 -04:00 committed by Daniil Gentili
parent 5b8169f7dc
commit 26352d0e39
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 27 additions and 0 deletions

View File

@ -787,12 +787,18 @@ class ForeachAnalyzer
$statements_analyzer->addSuppressedIssues(['PossiblyUndefinedMethod']);
}
$was_inside_call = $context->inside_call;
$context->inside_call = true;
\Psalm\Internal\Analyzer\Statements\Expression\Call\MethodCallAnalyzer::analyze(
$statements_analyzer,
$fake_method_call,
$context
);
$context->inside_call = $was_inside_call;
if (!in_array('PossiblyInvalidMethodCall', $suppressed_issues, true)) {
$statements_analyzer->removeSuppressedIssues(['PossiblyInvalidMethodCall']);
}

View File

@ -2203,6 +2203,27 @@ class UnusedVariableTest extends TestCase
return fn() => $e->getMessage();
}'
],
'useImmutableGetIteratorInForeach' => [
'<?php
/**
* @psalm-immutable
*/
class A implements IteratorAggregate
{
/**
* @return Iterator<int>
*/
public function getIterator() {
yield from [1, 2, 3];
}
}
$a = new A();
foreach ($a as $v) {
echo $v;
}'
],
];
}