From 9c6f380f6d24d47f12a9ca4f96901b06f8d3b2bf Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Thu, 27 Jan 2022 20:59:33 -0500 Subject: [PATCH] Simplify && handling --- .../Expression/BinaryOp/AndAnalyzer.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/AndAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/AndAnalyzer.php index 7e3937c38ac..d890838b441 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/AndAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/AndAnalyzer.php @@ -181,25 +181,22 @@ public static function analyze( } if ($context->if_context && !$context->inside_negation) { - $context->vars_in_scope = $right_context->vars_in_scope; $if_context = $context->if_context; - foreach ($right_context->vars_in_scope as $var_id => $type) { - if (!isset($if_context->vars_in_scope[$var_id])) { - $if_context->vars_in_scope[$var_id] = $type; - } elseif (isset($context->vars_in_scope[$var_id])) { - $if_context->vars_in_scope[$var_id] = $context->vars_in_scope[$var_id]; - } - } + $context->vars_in_scope = $right_context->vars_in_scope; + $if_context->vars_in_scope = array_merge( + $if_context->vars_in_scope, + $context->vars_in_scope + ); $if_context->referenced_var_ids = array_merge( + $if_context->referenced_var_ids, $context->referenced_var_ids, - $if_context->referenced_var_ids ); $if_context->assigned_var_ids = array_merge( + $if_context->assigned_var_ids, $context->assigned_var_ids, - $if_context->assigned_var_ids ); $if_context->reconciled_expression_clauses = array_merge( @@ -211,8 +208,8 @@ public static function analyze( ); $if_context->vars_possibly_in_scope = array_merge( + $if_context->vars_possibly_in_scope, $context->vars_possibly_in_scope, - $if_context->vars_possibly_in_scope ); $if_context->updateChecks($context);