diff --git a/src/Psalm/Internal/Analyzer/MethodAnalyzer.php b/src/Psalm/Internal/Analyzer/MethodAnalyzer.php index e2ae34f90..838c1a41e 100644 --- a/src/Psalm/Internal/Analyzer/MethodAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/MethodAnalyzer.php @@ -613,6 +613,7 @@ class MethodAnalyzer extends FunctionLikeAnalyzer if ($guide_method_storage->external_mutation_free && !$implementer_method_storage->external_mutation_free + && !$guide_method_storage->mutation_free_inferred ) { if (IssueBuffer::accepts( new MissingImmutableAnnotation( diff --git a/tests/ImmutableAnnotationTest.php b/tests/ImmutableAnnotationTest.php index 32a3bcce9..c9522cd8e 100644 --- a/tests/ImmutableAnnotationTest.php +++ b/tests/ImmutableAnnotationTest.php @@ -219,6 +219,23 @@ class ImmutableAnnotationTest extends TestCase } }' ], + 'allowMethodOverriding' => [ + 'a = $a; + } + + public function getA() : string { + return $this->a; + } + } + + /** @method string getA() */ + class B extends A {}', + ], ]; }