Skip to content

Commit

Permalink
Simplify context updates even more
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jul 17, 2022
1 parent d7d9ddc commit a32e63f
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions src/Psalm/Context.php
Expand Up @@ -459,7 +459,7 @@ public function update(
array $vars_to_update,
array &$updated_vars
): void {
foreach ($start_context->vars_in_scope as $var_id => $old_type) {
foreach ($start_context->vars_in_scope as $var_id => $_) {
// this is only true if there was some sort of type negation
if (in_array($var_id, $vars_to_update, true)) {
// if we're leaving, we're effectively deleting the possibility of the if types
Expand All @@ -469,30 +469,10 @@ public function update(

$existing_type = $this->vars_in_scope[$var_id] ?? null;

if (!$existing_type) {
if ($new_type) {
$this->vars_in_scope[$var_id] = clone $new_type;
$updated_vars[$var_id] = true;
}

continue;
}

$existing_type = clone $existing_type;

// if the type changed within the block of statements, process the replacement
// also never allow ourselves to remove all types from a union
if ((!$new_type || !$old_type->equals($new_type))
&& ($new_type || count($existing_type->getAtomicTypes()) > 1)
) {
if ($new_type && $new_type->from_docblock) {
$existing_type->setFromDocblock();
}

if (!$existing_type && $new_type) {
$this->vars_in_scope[$var_id] = clone $new_type;
$updated_vars[$var_id] = true;
}

$this->vars_in_scope[$var_id] = $existing_type;
}
}
}
Expand Down

0 comments on commit a32e63f

Please sign in to comment.