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:
parent
d387a1966c
commit
fdbea45534
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -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) {}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user