1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #5184 - remove this vars from parent context where possible

This commit is contained in:
Matt Brown 2021-02-09 10:23:22 -05:00
parent 03b54e369b
commit 2b9d307cab
2 changed files with 27 additions and 1 deletions

View File

@ -145,7 +145,11 @@ class MethodCallPurityAnalyzer
&& isset($context->vars_in_scope[$mutation_var_id])
&& !isset($class_storage->declaring_property_ids[$name]);
$context->remove($mutation_var_id);
$current_context = $context;
do {
$current_context->remove($mutation_var_id);
} while ($current_context = $current_context->parent_context);
if ($this_property_didnt_exist) {
$context->vars_in_scope[$mutation_var_id] = Type::getMixed();

View File

@ -2392,6 +2392,28 @@ class PropertyTypeTest extends TestCase
echo $bar->{$b} ?? null;
}',
],
'dontMemoizeConditionalAssignment' => [
'<?php
class A {}
class B {
protected ?A $a = null;
public function test(): void {
if (!$this->a) {
$this->mayBeSetA();
}
if ($this->a instanceof A) {
}
}
protected function mayBeSetA(): void {
if (mt_rand(0, 1)) {
$this->a = new A();
}
}
}'
],
];
}