Skip to content
Permalink
Browse files

Fix #2322 - don’t update outer context if elseif has no leaving state…

…ments
  • Loading branch information
muglug committed Nov 11, 2019
1 parent 589ab54 commit fbd1cf0a718f4e6ba9d09aedf7676d5349b27c8b
Showing with 30 additions and 10 deletions.
  1. +0 −10 src/Psalm/Internal/Analyzer/Statements/Block/IfAnalyzer.php
  2. +30 −0 tests/AssertTest.php
@@ -1123,8 +1123,6 @@ function ($carry, Clause $clause) {
}
}
$old_elseif_context = clone $elseif_context;
$pre_stmts_assigned_var_ids = $elseif_context->assigned_var_ids;
$elseif_context->assigned_var_ids = [];
$pre_stmts_possibly_assigned_var_ids = $elseif_context->possibly_assigned_var_ids;
@@ -1306,14 +1304,6 @@ function ($carry, Clause $clause) {
array_keys($negated_elseif_types),
$if_scope->updated_vars
);
} elseif ($entry_clauses && (count($entry_clauses) > 1 || !array_values($entry_clauses)[0]->wedge)) {
$outer_context->update(
$old_elseif_context,
$elseif_context,
false,
array_keys(\array_intersect_key($negated_elseif_types, $pre_conditional_context->vars_in_scope)),
$if_scope->updated_vars
);
}
}
@@ -407,6 +407,36 @@ public static function getDayName(int $dayNum): string {
}
}'
],
'assertPropertiesOfElseStatement' => [
'<?php
class C {
public string $a = "";
public string $b = "";
}
function testElse(C $obj) : void {
if ($obj->a === "foo") {
} elseif ($obj->b === "bar") {
} else if ($obj->b === "baz") {}
if ($obj->b === "baz") {}
}'
],
'assertPropertiesOfElseifStatement' => [
'<?php
class C {
public string $a = "";
public string $b = "";
}
function testElseif(C $obj) : void {
if ($obj->a === "foo") {
} elseif ($obj->b === "bar") {
} elseif ($obj->b === "baz") {}
if ($obj->b === "baz") {}
}'
],
];
}
}

0 comments on commit fbd1cf0

Please sign in to comment.
You can’t perform that action at this time.