1
0
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:
Brown 2019-12-11 13:09:27 -05:00
parent e476eed111
commit d2b99cbe77
2 changed files with 21 additions and 0 deletions

View File

@ -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;

View File

@ -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);
}'
],
];
}