From 596492a95a08ec3ba1f3dc0a652168e9f8507985 Mon Sep 17 00:00:00 2001 From: Brown Date: Sun, 23 Aug 2020 22:16:03 -0400 Subject: [PATCH] Only add pure when not overriding upstream --- .../Analyzer/FunctionLikeAnalyzer.php | 1 + .../PureAnnotationAdditionTest.php | 69 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php index d742d81ab..f98fc0898 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php @@ -585,6 +585,7 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer && ($this->function instanceof Function_ || $this->function instanceof ClassMethod) && $storage->params + && !$overridden_method_ids ) { $manipulator = FunctionDocblockManipulator::getForFunction( $project_analyzer, diff --git a/tests/FileManipulation/PureAnnotationAdditionTest.php b/tests/FileManipulation/PureAnnotationAdditionTest.php index 040d5b5bf..e5d65b38c 100644 --- a/tests/FileManipulation/PureAnnotationAdditionTest.php +++ b/tests/FileManipulation/PureAnnotationAdditionTest.php @@ -141,6 +141,75 @@ class PureAnnotationAdditionTest extends FileManipulationTest ['MissingPureAnnotation'], true, ], + 'dontAddInChildMethod' => [ + 'a; + } + } + + class B extends A { + public function foo(string $s) : string { + return $string; + } + }', + 'a; + } + } + + class B extends A { + public function foo(string $s) : string { + return $string; + } + }', + '7.4', + ['MissingPureAnnotation'], + true, + ], + 'doAddInOtherMethod' => [ + 'a; + } + } + + class B extends A { + public function bar(string $s) : string { + return $string; + } + }', + 'a; + } + } + + class B extends A { + /** + * @psalm-pure + */ + public function bar(string $s) : string { + return $string; + } + }', + '7.4', + ['MissingPureAnnotation'], + true, + ], ]; } }