diff --git a/src/Psalm/Internal/Visitor/CheckTrivialExprVisitor.php b/src/Psalm/Internal/Visitor/CheckTrivialExprVisitor.php index c9ce2fc631a..7a1f9319bf6 100644 --- a/src/Psalm/Internal/Visitor/CheckTrivialExprVisitor.php +++ b/src/Psalm/Internal/Visitor/CheckTrivialExprVisitor.php @@ -37,6 +37,7 @@ private function checkNonTrivialExpr(PhpParser\Node\Expr $node) || $node instanceof PhpParser\Node\Expr\Yield_ || $node instanceof PhpParser\Node\Expr\YieldFrom || $node instanceof PhpParser\Node\Expr\New_ + || $node instanceof PhpParser\Node\Expr\Cast\String_ ) { if (($node instanceof PhpParser\Node\Expr\FuncCall || $node instanceof PhpParser\Node\Expr\MethodCall diff --git a/tests/FileManipulation/UnusedVariableManipulationTest.php b/tests/FileManipulation/UnusedVariableManipulationTest.php index ac8acffb144..161e9334bec 100644 --- a/tests/FileManipulation/UnusedVariableManipulationTest.php +++ b/tests/FileManipulation/UnusedVariableManipulationTest.php @@ -587,6 +587,51 @@ function foo() : void { ['UnusedVariable'], true, ], + 'dontRemoveUsedToStringCall' => [ + '