From ce3f7fccd6ed3405938e5de7e2073cbd3b9e7c32 Mon Sep 17 00:00:00 2001 From: Evan Shaw Date: Wed, 15 Mar 2023 22:06:36 +1300 Subject: [PATCH] Set inside_call for eval expressions --- .../Analyzer/Statements/Expression/EvalAnalyzer.php | 3 +++ tests/UnusedCodeTest.php | 4 ++++ tests/UnusedVariableTest.php | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/EvalAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/EvalAnalyzer.php index e02ad2c6b..34160e58b 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/EvalAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/EvalAnalyzer.php @@ -26,7 +26,10 @@ class EvalAnalyzer PhpParser\Node\Expr\Eval_ $stmt, Context $context ): void { + $was_inside_call = $context->inside_call; + $context->inside_call = true; ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context); + $context->inside_call = $was_inside_call; $codebase = $statements_analyzer->getCodebase(); diff --git a/tests/UnusedCodeTest.php b/tests/UnusedCodeTest.php index 25a62f712..cf805c26e 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -709,6 +709,10 @@ class UnusedCodeTest extends TestCase return $i; }', ], + 'usedFunctionCallInEval' => [ + 'code' => ' [ 'code' => ' [ + 'code' => ' [ 'code' => '