diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfAnalyzer.php index 4bc308f58..3462b7ec5 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfAnalyzer.php @@ -1250,7 +1250,7 @@ class IfAnalyzer $old_elseif_context, $elseif_context, false, - array_keys($negated_elseif_types), + array_keys(\array_intersect_key($negated_elseif_types, $pre_conditional_context->vars_in_scope)), $if_scope->updated_vars ); } diff --git a/tests/TypeAlgebraTest.php b/tests/TypeAlgebraTest.php index 3cbeacdb4..7e171fc28 100644 --- a/tests/TypeAlgebraTest.php +++ b/tests/TypeAlgebraTest.php @@ -931,6 +931,25 @@ class TypeAlgebraTest extends TestCase return $a; }', ], + 'allowAssertionInElseif' => [ + 'b && $x->a) { + } elseif ($x->c) { + $a = true; + } + + if ($x->c) {} + if ($a) {} + }' + ], ]; }