Skip to content

Commit 0055aac

Browse files
janedbalondrejmirtes
authored andcommitted
RichParser: fix inline ignore with parenthesis inside comment
1 parent 5a73f07 commit 0055aac

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Parser/RichParser.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,9 @@ private function parseIdentifiers(string $text, int $ignorePos): array
313313

314314
if ($tokenType === IgnoreLexer::TOKEN_CLOSE_PARENTHESIS) {
315315
$openParenthesisCount--;
316-
$expected = [IgnoreLexer::TOKEN_COMMA, IgnoreLexer::TOKEN_END];
316+
if ($openParenthesisCount === 0) {
317+
$expected = [IgnoreLexer::TOKEN_COMMA, IgnoreLexer::TOKEN_END];
318+
}
317319
continue;
318320
}
319321

tests/PHPStan/Parser/RichParserTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,22 @@ public function dataLinesToIgnore(): iterable
221221
2 => ['identifier', 'identifier2', 'identifier3'],
222222
],
223223
];
224+
225+
yield [
226+
'<?php' . PHP_EOL .
227+
'test(); // @phpstan-ignore identifier (comment with inner (parenthesis))' . PHP_EOL,
228+
[
229+
2 => ['identifier'],
230+
],
231+
];
232+
233+
yield [
234+
'<?php' . PHP_EOL .
235+
'test(); // @phpstan-ignore identifier ((((multi!))))' . PHP_EOL,
236+
[
237+
2 => ['identifier'],
238+
],
239+
];
224240
}
225241

226242
/**

0 commit comments

Comments
 (0)