diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseAnalyzer.php index 094b3fcaeaa..31fca6dc0f7 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseAnalyzer.php @@ -169,7 +169,7 @@ public static function analyze( $original_context, $new_assigned_var_ids, $new_possibly_assigned_var_ids, - [], + $if_scope->if_cond_changed_var_ids, true, ); diff --git a/tests/TypeReconciliation/ConditionalTest.php b/tests/TypeReconciliation/ConditionalTest.php index ff8fed4dc5b..cca5bee0fd0 100644 --- a/tests/TypeReconciliation/ConditionalTest.php +++ b/tests/TypeReconciliation/ConditionalTest.php @@ -2974,6 +2974,72 @@ function bar($m): void } ', ], + 'hypotheticalElseDoesNotLeak' => [ + 'code' => <<<'PHP' + [ + '$a===' => '1', + ], + ], + 'ifDoesNotLeak' => [ + 'code' => <<<'PHP' + [ + '$a===' => '1', + ], + ], + 'ifElseDoesNotLeak' => [ + 'code' => <<<'PHP' + [ + '$a===' => '1', + ], + ], + 'ifElseInvertedDoesNotLeak' => [ + 'code' => <<<'PHP' + [ + '$a===' => '1', + ], + ], + 'ifNotIssetDoesNotLeakArrayAssertions' => [ + 'code' => <<<'PHP' + [ 'code' => '