diff --git a/src/Psalm/Context.php b/src/Psalm/Context.php index 0aa199210..203f480f1 100644 --- a/src/Psalm/Context.php +++ b/src/Psalm/Context.php @@ -213,6 +213,11 @@ class Context // also never allow ourselves to remove all types from a union if ((string)$old_type !== (string)$new_type && ($new_type || count($context_type->types) > 1)) { $context_type->substitute($old_type, $new_type); + + if ($new_type && $new_type->from_docblock) { + $context_type->setFromDocblock(); + } + $updated_vars[$var] = true; } } diff --git a/tests/RedundantConditionTest.php b/tests/RedundantConditionTest.php index 013369a9e..767453f08 100644 --- a/tests/RedundantConditionTest.php +++ b/tests/RedundantConditionTest.php @@ -95,6 +95,25 @@ class RedundantConditionTest extends TestCase } }', ], + 'noRedundantConditionTypeReplacementWithDocblock' => [ + '