From a1ea5c38c2ecdeeea9ed3ea5db25272c46e867e2 Mon Sep 17 00:00:00 2001 From: Brown Date: Mon, 9 Sep 2019 11:20:47 -0400 Subject: [PATCH] Clean up unnecessary annotation Ref #2111 --- .../Statements/Expression/AssignmentAnalyzer.php | 4 ++-- tests/ImmutableAnnotationTest.php | 9 --------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php index b4e8d5238..c5a937300 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php @@ -627,8 +627,8 @@ class AssignmentAnalyzer $method_pure_compatible = !empty($assign_var->var->inferredType->external_mutation_free) || isset($assign_var->var->pure); - if (($context->mutation_free - || ($context->external_mutation_free && !$method_pure_compatible)) + if (($context->mutation_free || $context->external_mutation_free) + && !$method_pure_compatible && !$context->collect_mutations && !$context->collect_initializations ) { diff --git a/tests/ImmutableAnnotationTest.php b/tests/ImmutableAnnotationTest.php index 3ff21062c..89449750f 100644 --- a/tests/ImmutableAnnotationTest.php +++ b/tests/ImmutableAnnotationTest.php @@ -125,9 +125,6 @@ class ImmutableAnnotationTest extends TestCase $this->bar = $bar; } - /** - * @psalm-external-mutation-free - */ public function withBar(string $bar): self { $new = new Foo("hello"); /** @psalm-suppress InaccessibleProperty */ @@ -149,9 +146,6 @@ class ImmutableAnnotationTest extends TestCase $this->bar = $bar; } - /** - * @psalm-external-mutation-free - */ public function withBar(string $bar): self { $new = clone $this; /** @psalm-suppress InaccessibleProperty */ @@ -280,9 +274,6 @@ class ImmutableAnnotationTest extends TestCase $this->bar = $bar; } - /** - * @psalm-external-mutation-free - */ public function withBar(Bar $b): Bar { $new = clone $b; $b->a = $this->bar;