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:
parent
564cebbaad
commit
6502eba658
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user