diff --git a/src/Psalm/Context.php b/src/Psalm/Context.php index 98df337c6..25c802d96 100644 --- a/src/Psalm/Context.php +++ b/src/Psalm/Context.php @@ -513,7 +513,7 @@ class Context * @param Clause[] $clauses * @param array $changed_var_ids * - * @return array{0: list, list} + * @return array{list, list} * * @psalm-pure */ diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/OrAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/OrAnalyzer.php index 151bfed0d..fd9dcf521 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/OrAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/OrAnalyzer.php @@ -250,6 +250,9 @@ class OrAnalyzer $pre_referenced_var_ids = $right_context->referenced_var_ids; $right_context->referenced_var_ids = []; + $pre_assigned_var_ids = $right_context->assigned_var_ids; + $right_context->assigned_var_ids = []; + if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->right, $right_context) === false) { return false; } @@ -257,6 +260,9 @@ class OrAnalyzer $right_referenced_var_ids = $right_context->referenced_var_ids; $right_context->referenced_var_ids = array_merge($pre_referenced_var_ids, $right_referenced_var_ids); + $right_assigned_var_ids = $right_context->assigned_var_ids; + $right_context->assigned_var_ids = array_merge($pre_assigned_var_ids, $right_assigned_var_ids); + $right_cond_id = \spl_object_id($stmt->right); $right_clauses = FormulaGenerator::getFormula( @@ -268,6 +274,11 @@ class OrAnalyzer $codebase ); + $clauses_for_right_analysis = Context::removeReconciledClauses( + $clauses_for_right_analysis, + $right_assigned_var_ids + )[0]; + $combined_right_clauses = Algebra::simplifyCNF( array_merge($clauses_for_right_analysis, $right_clauses) ); diff --git a/tests/TypeReconciliation/AssignmentInConditionalTest.php b/tests/TypeReconciliation/AssignmentInConditionalTest.php index 326eb7b24..3eed18808 100644 --- a/tests/TypeReconciliation/AssignmentInConditionalTest.php +++ b/tests/TypeReconciliation/AssignmentInConditionalTest.php @@ -430,6 +430,25 @@ class AssignmentInConditionalTest extends \Psalm\Tests\TestCase echo $a; }', ], + 'assignmentInBranchWithReference' => [ + '