From f8b4b12ec28127a6823742f1cf3b5562136a0a4e Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Mon, 13 May 2019 09:04:26 -0400 Subject: [PATCH] =?UTF-8?q?Fix=20#1622=20-=20don=E2=80=99t=20update=20retu?= =?UTF-8?q?rn=20types=20in=20docblocks=20when=20overridden=20elsewhere?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FunctionLike/ReturnTypeAnalyzer.php | 11 ++- .../ReturnTypeManipulationTest.php | 95 +++++++++++++++++++ 2 files changed, 104 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php index 1930449d1..e1502e0e9 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php @@ -344,13 +344,20 @@ class ReturnTypeAnalyzer return null; } - if ($codebase->alter_code && isset($project_analyzer->getIssuesToFix()['InvalidReturnType'])) { + if ($codebase->alter_code + && isset($project_analyzer->getIssuesToFix()['InvalidReturnType']) + && !in_array('InvalidReturnType', $suppressed_issues) + ) { self::addOrUpdateReturnType( $function, $project_analyzer, Type::getVoid(), $source, - $function_like_analyzer + $function_like_analyzer, + $compatible_method_ids + || (($project_analyzer->only_replace_php_types_with_non_docblock_types + || $unsafe_return_type) + && $inferred_return_type->from_docblock) ); return null; diff --git a/tests/FileManipulation/ReturnTypeManipulationTest.php b/tests/FileManipulation/ReturnTypeManipulationTest.php index d7ca111f8..d88e051bf 100644 --- a/tests/FileManipulation/ReturnTypeManipulationTest.php +++ b/tests/FileManipulation/ReturnTypeManipulationTest.php @@ -1037,6 +1037,101 @@ class ReturnTypeManipulationTest extends FileManipulationTest ['LessSpecificReturnType'], true, ], + 'addMissingReturnTypeWhenParentHasNone' => [ + ' [ + ' [ + '