mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Add possibly defined vars in binary op analysis
This commit is contained in:
parent
e476eed111
commit
d2b99cbe77
@ -249,6 +249,11 @@ class BinaryOpAnalyzer
|
||||
)
|
||||
);
|
||||
|
||||
$if_context->vars_possibly_in_scope = array_merge(
|
||||
$context->vars_possibly_in_scope,
|
||||
$if_context->vars_possibly_in_scope
|
||||
);
|
||||
|
||||
$if_context->updateChecks($context);
|
||||
} else {
|
||||
$context->vars_in_scope = $left_context->vars_in_scope;
|
||||
|
@ -2222,6 +2222,22 @@ class ConditionalTest extends \Psalm\Tests\TestCase
|
||||
return $v;
|
||||
}'
|
||||
],
|
||||
'possiblyDefinedVarInAssertion' => [
|
||||
'<?php
|
||||
class A {
|
||||
public function test() : bool { return true; }
|
||||
}
|
||||
|
||||
function getMaybeA() : ?A { return rand(0, 1) ? new A : null; }
|
||||
|
||||
function foo() : void {
|
||||
if (rand(0, 10) && ($a = getMaybeA()) && !$a->test()) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo isset($a);
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user