Skip to content

Commit 414ae57

Browse files
committed
Properties in enums are parse errors, not compile errors
1 parent 190ebc0 commit 414ae57

File tree

4 files changed

+159
-2
lines changed

4 files changed

+159
-2
lines changed

src/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3593,8 +3593,8 @@ private function isEnumMemberDeclarationStart($token) {
35933593
case TokenKind::PublicKeyword:
35943594
case TokenKind::ProtectedKeyword:
35953595
case TokenKind::PrivateKeyword:
3596-
// case TokenKind::VarKeyword:
3597-
// case TokenKind::ReadonlyKeyword:
3596+
case TokenKind::VarKeyword:
3597+
case TokenKind::ReadonlyKeyword:
35983598
case TokenKind::StaticKeyword:
35993599
case TokenKind::AbstractKeyword:
36003600
case TokenKind::FinalKeyword:

tests/cases/parser81/enums7.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
// Adding properties to an enum is a compile error, not a parse error.
3+
enum Invalid {
4+
var $notAllowed;
5+
readonly $alsoNotAllowed;
6+
public static $notAllowedStatic;
7+
}

tests/cases/parser81/enums7.php.diag

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

tests/cases/parser81/enums7.php.tree

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"SourceFileNode": {
3+
"statementList": [
4+
{
5+
"InlineHtml": {
6+
"scriptSectionEndTag": null,
7+
"text": null,
8+
"scriptSectionStartTag": {
9+
"kind": "ScriptSectionStartTag",
10+
"textLength": 6
11+
}
12+
}
13+
},
14+
{
15+
"EnumDeclaration": {
16+
"attributes": null,
17+
"enumKeyword": {
18+
"kind": "EnumKeyword",
19+
"textLength": 4
20+
},
21+
"name": {
22+
"kind": "Name",
23+
"textLength": 7
24+
},
25+
"colonToken": null,
26+
"enumType": null,
27+
"enumMembers": {
28+
"EnumMembers": {
29+
"openBrace": {
30+
"kind": "OpenBraceToken",
31+
"textLength": 1
32+
},
33+
"enumMemberDeclarations": [
34+
{
35+
"PropertyDeclaration": {
36+
"attributes": null,
37+
"modifiers": [
38+
{
39+
"kind": "VarKeyword",
40+
"textLength": 3
41+
}
42+
],
43+
"questionToken": null,
44+
"typeDeclarationList": null,
45+
"propertyElements": {
46+
"ExpressionList": {
47+
"children": [
48+
{
49+
"Variable": {
50+
"dollar": null,
51+
"name": {
52+
"kind": "VariableName",
53+
"textLength": 11
54+
}
55+
}
56+
}
57+
]
58+
}
59+
},
60+
"semicolon": {
61+
"kind": "SemicolonToken",
62+
"textLength": 1
63+
}
64+
}
65+
},
66+
{
67+
"PropertyDeclaration": {
68+
"attributes": null,
69+
"modifiers": [
70+
{
71+
"kind": "ReadonlyKeyword",
72+
"textLength": 8
73+
}
74+
],
75+
"questionToken": null,
76+
"typeDeclarationList": null,
77+
"propertyElements": {
78+
"ExpressionList": {
79+
"children": [
80+
{
81+
"Variable": {
82+
"dollar": null,
83+
"name": {
84+
"kind": "VariableName",
85+
"textLength": 15
86+
}
87+
}
88+
}
89+
]
90+
}
91+
},
92+
"semicolon": {
93+
"kind": "SemicolonToken",
94+
"textLength": 1
95+
}
96+
}
97+
},
98+
{
99+
"PropertyDeclaration": {
100+
"attributes": null,
101+
"modifiers": [
102+
{
103+
"kind": "PublicKeyword",
104+
"textLength": 6
105+
},
106+
{
107+
"kind": "StaticKeyword",
108+
"textLength": 6
109+
}
110+
],
111+
"questionToken": null,
112+
"typeDeclarationList": null,
113+
"propertyElements": {
114+
"ExpressionList": {
115+
"children": [
116+
{
117+
"Variable": {
118+
"dollar": null,
119+
"name": {
120+
"kind": "VariableName",
121+
"textLength": 17
122+
}
123+
}
124+
}
125+
]
126+
}
127+
},
128+
"semicolon": {
129+
"kind": "SemicolonToken",
130+
"textLength": 1
131+
}
132+
}
133+
}
134+
],
135+
"closeBrace": {
136+
"kind": "CloseBraceToken",
137+
"textLength": 1
138+
}
139+
}
140+
}
141+
}
142+
}
143+
],
144+
"endOfFileToken": {
145+
"kind": "EndOfFileToken",
146+
"textLength": 0
147+
}
148+
}
149+
}

0 commit comments

Comments
 (0)