diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodCallPurityAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodCallPurityAnalyzer.php index 1b5859bd660..0fde9d86617 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodCallPurityAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodCallPurityAnalyzer.php @@ -158,7 +158,7 @@ public static function analyze( && !isset($class_storage->declaring_property_ids[$name]); if ($this_property_didnt_exist) { - $context->vars_in_scope[$mutation_var_id] = Type::getMixed(); + unset($context->vars_in_scope[$mutation_var_id]); } else { $new_type = AssignmentAnalyzer::getExpandedPropertyType( $codebase, diff --git a/tests/MagicPropertyTest.php b/tests/MagicPropertyTest.php index a6b9876dd27..445b3ee1f12 100644 --- a/tests/MagicPropertyTest.php +++ b/tests/MagicPropertyTest.php @@ -731,6 +731,41 @@ public function __set(string $_prop, $_value) {} $a->type = A::TYPE_B; ', ], + 'impureMethodTest' => [ + 'code' => ' $errors + * + * @psalm-seal-properties + */ + final class OrganizationObject { + + public function __get(string $key) + { + return []; + } + + /** + * @param mixed $a + */ + public function __set(string $key, $a): void + { + } + + public function updateErrors(): void { + /** @var array */ + $errors = []; + $this->errors = $errors; + } + /** @return array */ + public function updateStatus(): array { + $_ = $this->errors; + $this->updateErrors(); + $errors = $this->errors; + return $errors; + } + }' + ] ]; }