From 70a83c8e2ab0575c0a3be96ef0e2eff80a8b4d71 Mon Sep 17 00:00:00 2001 From: robchett Date: Thu, 26 Oct 2023 14:57:48 +0100 Subject: [PATCH] Skip inline docblocks like {@see ...} --- src/Psalm/Internal/Type/ParseTreeCreator.php | 24 +++++++++++++++++--- tests/MethodSignatureTest.php | 9 ++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Internal/Type/ParseTreeCreator.php b/src/Psalm/Internal/Type/ParseTreeCreator.php index eb57c1ad41c..737b5ac3f1b 100644 --- a/src/Psalm/Internal/Type/ParseTreeCreator.php +++ b/src/Psalm/Internal/Type/ParseTreeCreator.php @@ -31,6 +31,7 @@ use function in_array; use function preg_match; use function strlen; +use function strpos; use function strtolower; /** @@ -825,13 +826,30 @@ private function handleValue(array $type_token): void break; case '{': + ++$this->t; + + $nexter_token = $this->t + 1 < $this->type_token_count ? $this->type_tokens[$this->t + 1] : null; + + if ($nexter_token && strpos($nexter_token[0], '@') !== false) { + $this->t = $this->type_token_count; + if ($type_token[0] === '$this') { + $type_token[0] = 'static'; + } + + $new_leaf = new Value( + $type_token[0], + $type_token[1], + $type_token[1] + strlen($type_token[0]), + $type_token[2] ?? null, + $new_parent, + ); + break; + } + $new_leaf = new KeyedArrayTree( $type_token[0], $new_parent, ); - ++$this->t; - - $nexter_token = $this->t + 1 < $this->type_token_count ? $this->type_tokens[$this->t + 1] : null; if ($nexter_token !== null && $nexter_token[0] === '}') { $new_leaf->terminated = true; diff --git a/tests/MethodSignatureTest.php b/tests/MethodSignatureTest.php index f20e73a03e5..e60ddb4c627 100644 --- a/tests/MethodSignatureTest.php +++ b/tests/MethodSignatureTest.php @@ -400,6 +400,15 @@ public static function foo() { '$b' => 'B', ], ], + 'returnIgnoresInlineComments' => [ + 'code' => ' [ 'code' => '