diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php index debb27e87..72dbba845 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php @@ -528,18 +528,18 @@ final class AssignmentAnalyzer } if ($context->vars_in_scope[$var_id]->isNever()) { - if (IssueBuffer::accepts( + if (!IssueBuffer::accepts( new NoValue( 'All possible types for this assignment were invalidated - This may be dead code', new CodeLocation($statements_analyzer->getSource(), $assign_var), ), $statements_analyzer->getSuppressedIssues(), )) { - return false; + // if the error is suppressed, do not treat it as never anymore + $context->vars_in_scope[$var_id] = Type::getMixed(); + $context->has_returned = false; } - $context->vars_in_scope[$var_id] = Type::getNever(); - $context->inside_assignment = $was_in_assignment; return $context->vars_in_scope[$var_id]; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php index cd3e590b8..4f184b6ce 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php @@ -806,13 +806,16 @@ final class ArgumentAnalyzer } if ($input_type->isNever()) { - IssueBuffer::maybeAdd( + if (!IssueBuffer::accepts( new NoValue( 'All possible types for this argument were invalidated - This may be dead code', $arg_location, ), $statements_analyzer->getSuppressedIssues(), - ); + )) { + // if the error is suppressed, do not treat it as exited anymore + $context->has_returned = false; + } return null; } diff --git a/tests/UnusedCodeTest.php b/tests/UnusedCodeTest.php index ef570f8a6..b6857577c 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -476,13 +476,13 @@ class UnusedCodeTest extends TestCase return new a; } } - + final class b { public function test(): a { return new a; } } - + function process(b $handler): a { if (\extension_loaded("fdsfdsfd")) { return $handler->test(); @@ -1323,6 +1323,38 @@ class UnusedCodeTest extends TestCase new A; PHP, ], + 'callNeverReturnsSuppressed' => [ + 'code' => ' [ + 'code' => '