Skip to content

Commit bb03390

Browse files
committed
PHP 8.1 | Tokenizer/PHP: bugfix - name of typed enum tokenized as T_GOTO_LABEL
Follow up on 3478. When an `enum` would be backed by a type and the colon would directly follow the name of the `enum`, the name would be incorrectly tokenized (including the colon) as `T_GOTO_LABEL`. Discovered while reviewing 3482 Also related to 3161
1 parent 498a939 commit bb03390

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/Tokenizers/PHP.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,7 @@ function return types. We want to keep the parenthesis map clean,
19051905
T_OPEN_TAG => true,
19061906
T_OPEN_CURLY_BRACKET => true,
19071907
T_INLINE_THEN => true,
1908+
T_ENUM => true,
19081909
];
19091910

19101911
for ($x = ($newStackPtr - 1); $x > 0; $x--) {
@@ -1915,6 +1916,7 @@ function return types. We want to keep the parenthesis map clean,
19151916

19161917
if ($finalTokens[$x]['code'] !== T_CASE
19171918
&& $finalTokens[$x]['code'] !== T_INLINE_THEN
1919+
&& $finalTokens[$x]['code'] !== T_ENUM
19181920
) {
19191921
$finalTokens[$newStackPtr] = [
19201922
'content' => $token[1].':',

tests/Core/Tokenizer/GotoLabelTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@ switch (true) {
5151
// Do something.
5252
break;
5353
}
54+
55+
/* testNotGotoDeclarationEnumWithType */
56+
enum Suit: string implements Colorful, CardGame {}

tests/Core/Tokenizer/GotoLabelTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ public function dataNotAGotoDeclaration()
163163
'/* testNotGotoDeclarationGlobalConstantInTernary */',
164164
'CONST_B',
165165
],
166+
[
167+
'/* testNotGotoDeclarationEnumWithType */',
168+
'Suit',
169+
],
166170
];
167171

168172
}//end dataNotAGotoDeclaration()

0 commit comments

Comments
 (0)