diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php index 2cf10dc19..6331b7ec4 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php @@ -1906,8 +1906,8 @@ class ClassLikeNodeScanner $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( diff --git a/tests/TypeAnnotationTest.php b/tests/TypeAnnotationTest.php index 497a051ac..a6d96fc9b 100644 --- a/tests/TypeAnnotationTest.php +++ b/tests/TypeAnnotationTest.php @@ -653,6 +653,14 @@ class TypeAnnotationTest extends TestCase '$output===' => 'list<1|2>', ], ], + 'handlesTypeWhichEndsWithRoundBracket' => [ + 'code' => ') + */ + class A {} + ', + ], ]; }