diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php index 72dbba84522..904d801fbf7 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php @@ -536,13 +536,15 @@ public static function analyze( $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; - } - - $context->inside_assignment = $was_in_assignment; + } else { + $context->inside_assignment = $was_in_assignment; - return $context->vars_in_scope[$var_id]; + return $context->vars_in_scope[$var_id]; + } } if ($statements_analyzer->data_flow_graph) { diff --git a/tests/UnusedCodeTest.php b/tests/UnusedCodeTest.php index b6857577c19..947ff34de36 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -1332,10 +1332,6 @@ public function b(): void {} */ 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 @@ function bar(mixed $s) : string { */ function foo() : void {} + /** @psalm-suppress UnusedParam */ function bar(mixed $s) : void {} /** @psalm-suppress NoValue */