Skip to content

Commit

Permalink
Fix vimeo#3625 - getIterator call is used inside loop
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug authored and danog committed Jan 29, 2021
1 parent 5b8169f commit 26352d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -787,12 +787,18 @@ public static function handleIterable(
$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']);
}
Expand Down
21 changes: 21 additions & 0 deletions tests/UnusedVariableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2203,6 +2203,27 @@ function test(Exception $e): callable {
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;
}'
],
];
}

Expand Down

0 comments on commit 26352d0

Please sign in to comment.