From 10272c2da1d3590b48c6eaaa4fc8a9f459754baa Mon Sep 17 00:00:00 2001 From: Brown Date: Tue, 14 May 2019 17:41:22 -0400 Subject: [PATCH] =?UTF-8?q?Fix=20#1636=20-=20don=E2=80=99t=20allow=20inval?= =?UTF-8?q?id=20phpdoc=20to=20be=20outputted?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FunctionDocblockManipulator.php | 2 +- src/Psalm/Type/Atomic/GenericTrait.php | 2 +- .../ReturnTypeManipulationTest.php | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php b/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php index 4807defa8..fe434eb70 100644 --- a/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php +++ b/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php @@ -243,7 +243,7 @@ class FunctionDocblockManipulator */ public function setReturnType($php_type, $new_type, $phpdoc_type, $is_php_compatible, $description) { - $new_type = str_replace(['', '', ''], '', $new_type); + $new_type = str_replace(['', ''], '', $new_type); $this->new_php_return_type = $php_type; $this->new_phpdoc_return_type = $phpdoc_type; diff --git a/src/Psalm/Type/Atomic/GenericTrait.php b/src/Psalm/Type/Atomic/GenericTrait.php index eb7c7177c..747a4960f 100644 --- a/src/Psalm/Type/Atomic/GenericTrait.php +++ b/src/Psalm/Type/Atomic/GenericTrait.php @@ -73,7 +73,7 @@ trait GenericTrait $value_type = $this->type_params[1]; - if ($value_type->isMixed()) { + if ($value_type->isMixed() || $value_type->isEmpty()) { return $base_value; } diff --git a/tests/FileManipulation/ReturnTypeManipulationTest.php b/tests/FileManipulation/ReturnTypeManipulationTest.php index c894e459e..48aaedce4 100644 --- a/tests/FileManipulation/ReturnTypeManipulationTest.php +++ b/tests/FileManipulation/ReturnTypeManipulationTest.php @@ -1208,6 +1208,25 @@ class ReturnTypeManipulationTest extends FileManipulationTest false, false, ], + 'noEmptyArrayAnnotation' => [ + ' + */ + function foo(): array { + return []; + }', + '7.3', + ['MissingReturnType'], + false, + ], + ]; } }