From 549b200aa7a40e8e1b352d3f1a05869b208ea0d7 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Sun, 4 Oct 2020 17:53:26 -0400 Subject: [PATCH] Remove mixed assignment issue --- .../Analyzer/Statements/Block/IfAnalyzer.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfAnalyzer.php index 1986cd8ba..bd4b30413 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfAnalyzer.php @@ -882,6 +882,33 @@ class IfAnalyzer ); } + foreach ($changed_var_ids as $var_id => $_) { + $first_appearance = $statements_analyzer->getFirstAppearance($var_id); + + if ($first_appearance + && isset($outer_context->vars_in_scope[$var_id]) + && isset($outer_context_vars_reconciled[$var_id]) + && $outer_context->vars_in_scope[$var_id]->hasMixed() + && !$outer_context_vars_reconciled[$var_id]->hasMixed() + ) { + if (!$outer_context->collect_initializations + && !$outer_context->collect_mutations + && $statements_analyzer->getFilePath() === $statements_analyzer->getRootFilePath() + && (!(($parent_source = $statements_analyzer->getSource()) + instanceof \Psalm\Internal\Analyzer\FunctionLikeAnalyzer) + || !$parent_source->getSource() instanceof \Psalm\Internal\Analyzer\TraitAnalyzer) + ) { + $codebase->analyzer->decrementMixedCount($statements_analyzer->getFilePath()); + } + + IssueBuffer::remove( + $statements_analyzer->getFilePath(), + 'MixedAssignment', + $first_appearance->raw_file_start + ); + } + } + $outer_context->vars_in_scope = $outer_context_vars_reconciled; $mic_drop = true; }