1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Propagate mutation removal up the context parent tree

Fixes #5231
This commit is contained in:
Matt Brown 2021-02-25 18:11:58 -05:00
parent 71064cf258
commit 924f6b6f94
2 changed files with 36 additions and 0 deletions

View File

@ -712,6 +712,10 @@ class Context
}
$this->clauses = $clauses_to_keep;
if ($this->parent_context) {
$this->parent_context->removeMutableObjectVars();
}
}
public function updateChecks(Context $op_context): void

View File

@ -114,6 +114,38 @@ class PropertyTypeTest extends TestCase
$this->analyzeFile('somefile.php', new Context());
}
public function testFooBar(): void
{
Config::getInstance()->remember_property_assignments_after_call = false;
$this->addFile(
'somefile.php',
'<?php
class A {
private ?int $bar = null;
public function baz(): void
{
$this->bar = null;
foreach (range(1, 5) as $part) {
if ($part === 3) {
$this->foo();
}
}
if ($this->bar === null) {}
}
private function foo() : void {
$this->bar = 5;
}
}'
);
$this->analyzeFile('somefile.php', new Context());
}
public function testForgetFinalMethodCalls(): void
{
Config::getInstance()->remember_property_assignments_after_call = false;