Skip to content

Commit

Permalink
Allow inline comments in typedef shapes
Browse files Browse the repository at this point in the history
Fixes #10492
  • Loading branch information
weirdan committed Jan 31, 2024
1 parent 215d62e commit 9314afe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1913,10 +1913,6 @@ private static function getTypeAliasesFromCommentLines(
continue;
}

$var_line = preg_replace('/[ \t]+/', ' ', preg_replace('@^[ \t]*\*@m', '', $var_line));
$var_line = preg_replace('/,\n\s+\}/', '}', $var_line);
$var_line = str_replace("\n", '', $var_line);

$var_line_parts = preg_split('/( |=)/', $var_line, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);

if (!$var_line_parts) {
Expand Down Expand Up @@ -1949,7 +1945,7 @@ private static function getTypeAliasesFromCommentLines(
array_shift($var_line_parts);
}

$type_string = str_replace("\n", '', implode('', $var_line_parts));
$type_string = implode('', $var_line_parts);
try {
$type_string = CommentAnalyzer::splitDocLine($type_string)[0];
} catch (DocblockParseException $e) {
Expand Down
17 changes: 17 additions & 0 deletions tests/TypeAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,23 @@ public function f(array $foo): void {
'ignored_issues' => [],
'php_version' => '8.1',
],
'inlineComments' => [
'code' => <<<'PHP'
<?php
/**
* @psalm-type Foo=array{
* a: string, // comment
* b: string, // comment
* }
*/
class A {
/**
* @psalm-param Foo $foo
*/
public function bar(array $foo): void {}
}
PHP,
],
];
}

Expand Down

0 comments on commit 9314afe

Please sign in to comment.