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:
parent
cd33430616
commit
d29c7b42d9
@ -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()),
|
||||
|
@ -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];
|
||||
}
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user