From fbc51a098420bf34abf509af91b90ec0e58d6eab Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 15 Feb 2024 13:34:28 +0100 Subject: [PATCH] Improve parsing of psalm-type --- .../Reflector/ClassLikeNodeScanner.php | 5 +---- tests/AnnotationTest.php | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php index 999f95df554..79092c8003d 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php @@ -1948,11 +1948,8 @@ private static function getTypeAliasesFromCommentLines( continue; } - if ($var_line_parts[0] === ' ') { - array_shift($var_line_parts); - } - $type_string = implode('', $var_line_parts); + $type_string = ltrim($type_string, "* \n\r"); try { $type_string = CommentAnalyzer::splitDocLine($type_string)[0]; } catch (DocblockParseException $e) { diff --git a/tests/AnnotationTest.php b/tests/AnnotationTest.php index 64ebf674b4e..5b453b0f402 100644 --- a/tests/AnnotationTest.php +++ b/tests/AnnotationTest.php @@ -513,6 +513,28 @@ function example(string $_x) : void {}', */ class A {}', ], + 'multipeLineGenericArray2' => [ + 'code' => ' + */ + class A { + /** @return TRelAlternate */ + public function ret(): array { return []; } + } + + $_ = (new A)->ret(); + ', + 'assertions' => [ + '$_===' => 'list' + ], + ], 'builtInClassInAShape' => [ 'code' => '