Skip to content

Commit

Permalink
Add back necessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jan 26, 2022
1 parent 4ed899a commit 9461caa
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php
Expand Up @@ -28,8 +28,11 @@
use function array_intersect_key;
use function array_keys;
use function array_merge;
use function array_unique;
use function count;
use function in_array;
use function strpos;
use function substr;

/**
* @internal
Expand Down Expand Up @@ -172,6 +175,20 @@ public static function analyze(
array_keys($if_scope->negated_types)
);

$extra_vars_to_update = [];

// if there's an object-like array in there, we also need to update the root array variable
foreach ($vars_to_update as $var_id) {
$bracked_pos = strpos($var_id, '[');
if ($bracked_pos !== false) {
$extra_vars_to_update[] = substr($var_id, 0, $bracked_pos);
}
}

if ($extra_vars_to_update) {
$vars_to_update = array_unique(array_merge($extra_vars_to_update, $vars_to_update));
}

$outer_context->update(
$old_if_context,
$if_context,
Expand Down

0 comments on commit 9461caa

Please sign in to comment.