1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #2159 - only apply elseif conditions to vars that exist in main context

This commit is contained in:
Matthew Brown 2019-09-21 16:58:31 -04:00
parent d387a1966c
commit fdbea45534
2 changed files with 20 additions and 1 deletions

View File

@ -1250,7 +1250,7 @@ class IfAnalyzer
$old_elseif_context,
$elseif_context,
false,
array_keys($negated_elseif_types),
array_keys(\array_intersect_key($negated_elseif_types, $pre_conditional_context->vars_in_scope)),
$if_scope->updated_vars
);
}

View File

@ -931,6 +931,25 @@ class TypeAlgebraTest extends TestCase
return $a;
}',
],
'allowAssertionInElseif' => [
'<?php
class X {
public bool $a = false;
public bool $b = false;
public bool $c = false;
}
function foo(X $x) : void {
$a = false;
if ($x->b && $x->a) {
} elseif ($x->c) {
$a = true;
}
if ($x->c) {}
if ($a) {}
}'
],
];
}