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' => [ + ' [ + ' [ + '