Skip to content

Commit

Permalink
Do not strip the last ) bracket when parsing phpdoc type aliases.
Browse files Browse the repository at this point in the history
Fixes #6782

Reworked the regex logic to not check each grouping character separately. Removed the `^` character from the character list, which was likely unintended.
  • Loading branch information
pvandommelen committed Mar 5, 2023
1 parent dc4516b commit c72edef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Expand Up @@ -1906,8 +1906,8 @@ private static function getTypeAliasesFromCommentLines(

$type_string = str_replace("\n", '', implode('', $var_line_parts));

$type_string = preg_replace('/>[^>^\}]*$/', '>', $type_string, 1);
$type_string = preg_replace('/\}[^>^\}]*$/', '}', $type_string, 1);
// Strip any remaining characters after the last grouping character >, } or )
$type_string = preg_replace('/(?<=[>})])[^>})]*$/', '', $type_string, 1);

try {
$type_tokens = TypeTokenizer::getFullyQualifiedTokens(
Expand Down
8 changes: 8 additions & 0 deletions tests/TypeAnnotationTest.php
Expand Up @@ -653,6 +653,14 @@ public function doStuff(): array {
'$output===' => 'list<1|2>',
],
],
'handlesTypeWhichEndsWithRoundBracket' => [
'code' => '<?php
/**
* @psalm-type Foo=(iterable<mixed>)
*/
class A {}
',
],
];
}

Expand Down

0 comments on commit c72edef

Please sign in to comment.