From 85071b61a3955461e1493d13c1e0c5f3f78e7c01 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 24 Nov 2022 11:28:00 +0100 Subject: [PATCH 1/2] Fix #8748 --- .../Expression/Call/Method/MethodCallPurityAnalyzer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, From 5ac60ddea0427991ffbd5c25c8d984aad2ffbbea Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 24 Nov 2022 19:31:53 +0100 Subject: [PATCH 2/2] Add tests --- tests/MagicPropertyTest.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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; + } + }' + ] ]; }