Skip to content

Commit

Permalink
Skip inline docblocks like {@see ...}
Browse files Browse the repository at this point in the history
  • Loading branch information
robchett committed Nov 3, 2023
1 parent e76db14 commit 70a83c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/Psalm/Internal/Type/ParseTreeCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use function in_array;
use function preg_match;
use function strlen;
use function strpos;
use function strtolower;

/**
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions tests/MethodSignatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,15 @@ public static function foo() {
'$b' => 'B',
],
],
'returnIgnoresInlineComments' => [
'code' => '<?php
class A {
/** @return bool {@see true}*/
public static function foo():bool {
return true;
}
}',
],
'allowSomeCovariance' => [
'code' => '<?php
interface I1 {
Expand Down

0 comments on commit 70a83c8

Please sign in to comment.