Skip to content

Commit

Permalink
Propagate mutation removal up the context parent tree
Browse files Browse the repository at this point in the history
Fixes #5231
  • Loading branch information
muglug committed Feb 25, 2021
1 parent 71064cf commit 924f6b6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Psalm/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,10 @@ public function removeMutableObjectVars(): void
}

$this->clauses = $clauses_to_keep;

if ($this->parent_context) {
$this->parent_context->removeMutableObjectVars();
}
}

public function updateChecks(Context $op_context): void
Expand Down
32 changes: 32 additions & 0 deletions tests/PropertyTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,38 @@ function testX(X $x): void {
$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;
Expand Down

0 comments on commit 924f6b6

Please sign in to comment.