diff --git a/src/Psalm/Type/Reconciler.php b/src/Psalm/Type/Reconciler.php index d19abdf76..d9fb39867 100644 --- a/src/Psalm/Type/Reconciler.php +++ b/src/Psalm/Type/Reconciler.php @@ -105,7 +105,7 @@ class Reconciler foreach ($new_type_part_parts as $new_type_part_part) { $result_type_candidate = self::reconcileTypes( $new_type_part_part, - $result_type, + $result_type ? clone $result_type : null, $key, $statements_checker, $code_location && isset($referenced_var_ids[$key]) ? $code_location : null, diff --git a/tests/SwitchTypeTest.php b/tests/SwitchTypeTest.php index 114fa2a73..5a6e78a23 100644 --- a/tests/SwitchTypeTest.php +++ b/tests/SwitchTypeTest.php @@ -364,6 +364,51 @@ class SwitchTypeTest extends TestCase } }', ], + 'switchNullable1' => [ + ' [ + ' [ + ' [ + '