Skip to content
Permalink
Browse files

Fix #2591 - always remove changed var from parent clauses

Even when there are no child clauses due to an assertion
  • Loading branch information
muglug committed Jan 11, 2020
1 parent 5ddcab1 commit 1b7b71f2cab15b7c9ccfc6795487e2dfebc1fd18
Showing with 38 additions and 10 deletions.
  1. +8 −10 src/Psalm/Context.php
  2. +30 −0 tests/TypeReconciliation/TypeTest.php
@@ -657,16 +657,14 @@ public function removeDescendents(
return;
}

if ($this->clauses) {
$this->removeVarFromConflictingClauses(
$remove_var_id,
$existing_type->hasMixed()
|| ($new_type && $existing_type->from_docblock !== $new_type->from_docblock)
? null
: $new_type,
$statements_analyzer
);
}
$this->removeVarFromConflictingClauses(
$remove_var_id,
$existing_type->hasMixed()
|| ($new_type && $existing_type->from_docblock !== $new_type->from_docblock)
? null
: $new_type,
$statements_analyzer
);

$vars_to_remove = [];

@@ -1002,6 +1002,36 @@ function test($var): void {}
if ($optgroup["a"] !== "") {}'
],
'redefineArrayKeyInsideIsStringConditional' => [
'<?php
/**
* @param string|int $key
*/
function get($key, array $arr) : void {
if (!isset($arr[$key])) {
if (is_string($key)) {
$key = "p" . $key;
}
if (!isset($arr[$key])) {}
}
}'
],
'redefineArrayKeyInsideIsIntConditional' => [
'<?php
/**
* @param string|int $key
*/
function get($key, array $arr) : void {
if (!isset($arr[$key])) {
if (is_int($key)) {
$key++;
}
if (!isset($arr[$key])) {}
}
}'
],
];
}

0 comments on commit 1b7b71f

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