1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Don’t invalidate object vars after callmap functions

This commit is contained in:
Matt Brown 2018-04-13 11:24:59 -04:00
parent 564cebbaad
commit 6502eba658
2 changed files with 41 additions and 4 deletions

View File

@ -382,7 +382,10 @@ class FunctionCallChecker extends \Psalm\Checker\Statements\Expression\CallCheck
}
}
if (!$config->remember_property_assignments_after_call && !$context->collect_initializations) {
if (!$config->remember_property_assignments_after_call
&& !$in_call_map
&& !$context->collect_initializations
) {
$context->removeAllObjectVars();
}

View File

@ -27,10 +27,44 @@ class PropertyTypeTest extends TestCase
private $x;
public function getX(): int {
if ($this->x === null) {
$this->x = 0;
}
$this->x = 5;
$this->modifyX();
return $this->x;
}
private function modifyX(): void {
$this->x = null;
}
}'
);
$this->analyzeFile('somefile.php', new Context());
}
/**
* @return void
*/
public function testForgetPropertyAssignmentsInBranchWithThrow()
{
Config::getInstance()->remember_property_assignments_after_call = false;
$this->addFile(
'somefile.php',
'<?php
class X {
/** @var ?int **/
private $x;
public function getX(): int {
$this->x = 5;
if (rand(0, 1)) {
$this->modifyX();
throw new \Exception("bad");
}
return $this->x;
}