diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php index 72dbba845..904d801fb 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php @@ -536,13 +536,15 @@ final class AssignmentAnalyzer $statements_analyzer->getSuppressedIssues(), )) { // if the error is suppressed, do not treat it as never anymore - $context->vars_in_scope[$var_id] = Type::getMixed(); + $new_mutable = $context->vars_in_scope[$var_id]->getBuilder()->addType(new TMixed); + $new_mutable->removeType('never'); + $context->vars_in_scope[$var_id] = $new_mutable->freeze(); $context->has_returned = false; + } else { + $context->inside_assignment = $was_in_assignment; + + return $context->vars_in_scope[$var_id]; } - - $context->inside_assignment = $was_in_assignment; - - return $context->vars_in_scope[$var_id]; } if ($statements_analyzer->data_flow_graph) { diff --git a/tests/UnusedCodeTest.php b/tests/UnusedCodeTest.php index b6857577c..947ff34de 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -1332,10 +1332,6 @@ class UnusedCodeTest extends TestCase */ function foo() : void {} - function bar(mixed $s) : string { - return is_string($s) ? "hello" : "world"; - } - /** @psalm-suppress NoValue */ $a = foo(); print_r($a);', @@ -1349,6 +1345,7 @@ class UnusedCodeTest extends TestCase */ function foo() : void {} + /** @psalm-suppress UnusedParam */ function bar(mixed $s) : void {} /** @psalm-suppress NoValue */