From 25e7039f0216f7b37710079ffa63adcb3bbf76de Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Wed, 1 Jan 2020 18:33:12 -0500 Subject: [PATCH] The current method is used Fixes #2540 --- .../Analyzer/Statements/Block/ForeachAnalyzer.php | 4 ++++ tests/UnusedCodeTest.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php index a70caa711..d0c9c193b 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php @@ -860,12 +860,16 @@ class ForeachAnalyzer $statements_analyzer->addSuppressedIssues(['PossiblyInvalidMethodCall']); } + $context->inside_call = true; + \Psalm\Internal\Analyzer\Statements\Expression\Call\MethodCallAnalyzer::analyze( $statements_analyzer, $fake_method_call, $context ); + $context->inside_call = false; + if (!in_array('PossiblyInvalidMethodCall', $suppressed_issues, true)) { $statements_analyzer->removeSuppressedIssues(['PossiblyInvalidMethodCall']); } diff --git a/tests/UnusedCodeTest.php b/tests/UnusedCodeTest.php index 9f0e4d6a2..a41287c1f 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -669,6 +669,20 @@ class UnusedCodeTest extends TestCase new Foo();' ], + 'useIteratorMethodsWhenCallingForeach' => [ + 'current; + } + } + + $items = new IterableResult(); + + /** @psalm-suppress MixedAssignment */ + foreach ($items as $_item) {}' + ], ]; }