1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #1869 - don’t memoize magic properties after set

This commit is contained in:
Matthew Brown 2019-07-06 00:00:17 -04:00
parent cd33430616
commit d29c7b42d9
2 changed files with 39 additions and 0 deletions

View File

@ -365,6 +365,16 @@ class PropertyAssignmentAnalyzer
}
if ($assignment_value) {
if ($var_id) {
$context->removeVarFromConflictingClauses(
$var_id,
Type::getMixed(),
$statements_analyzer
);
unset($context->vars_in_scope[$var_id]);
}
$fake_method_call = new PhpParser\Node\Expr\MethodCall(
$stmt->var,
new PhpParser\Node\Identifier('__set', $stmt->name->getAttributes()),

View File

@ -517,6 +517,35 @@ class MagicPropertyTest extends TestCase
$a = new A();
$a->takesString($a->foo);',
],
'removeAssertionsAfterCall' => [
'<?php
class C {
/**
* @return mixed
*/
public function __get(string $name) {
return rand();
}
/**
* @param mixed $value
* @return void
*/
public function __set(string $name, $value) {}
public function main() : void {
if (!isset($this->a)) {
$this->a = ["something"];
/**
* @psalm-suppress MixedArrayAccess
* @psalm-suppress MixedArgument
*/
echo $this->a[0];
}
}
}'
],
];
}