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:
parent
5b8169f7dc
commit
26352d0e39
@ -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']);
|
||||
}
|
||||
|
@ -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;
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user