diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php index 999f95df5..828012fa7 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php @@ -78,6 +78,7 @@ use function get_class; use function implode; use function is_int; use function is_string; +use function ltrim; use function preg_match; use function preg_replace; use function preg_split; @@ -1932,7 +1933,7 @@ final class ClassLikeNodeScanner continue; } - if ($var_line_parts[0] === ' ') { + while (isset($var_line_parts[0]) && $var_line_parts[0] === ' ') { array_shift($var_line_parts); } @@ -1948,11 +1949,12 @@ final class ClassLikeNodeScanner continue; } - if ($var_line_parts[0] === ' ') { + while (isset($var_line_parts[0]) && $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 64ebf674b..4252e60b8 100644 --- a/tests/AnnotationTest.php +++ b/tests/AnnotationTest.php @@ -513,6 +513,28 @@ class AnnotationTest extends TestCase */ class A {}', ], + 'multipeLineGenericArray2' => [ + 'code' => ' + */ + class A { + /** @return TRelAlternate */ + public function ret(): array { return []; } + } + + $_ = (new A)->ret(); + ', + 'assertions' => [ + '$_===' => 'list', + ], + ], 'builtInClassInAShape' => [ 'code' => ' [ + 'code' => <<<'PHP' +