Skip to content

Commit e05480d

Browse files
author
Kirill Nesmeyanov
committed
Try to fix PHP 8.1 const in enums bug (php/php-src#8418)
1 parent fcdba19 commit e05480d

File tree

6 files changed

+48
-26
lines changed

6 files changed

+48
-26
lines changed

src/Node/Literal/LiteralKind.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use TypeLang\Parser\Node\Kind;
88

9+
const LITERAL_KIND = Kind::LITERAL_KIND;
10+
911
enum LiteralKind: int implements \JsonSerializable
1012
{
1113
/**
@@ -14,39 +16,39 @@ enum LiteralKind: int implements \JsonSerializable
1416
*
1517
* @internal
1618
*/
17-
case UNKNOWN = Kind::LITERAL_KIND;
19+
case UNKNOWN = LITERAL_KIND;
1820

1921
/**
2022
* Denotes any {@see bool} type consisting of the
2123
* literal {@see true} and {@see false} values.
2224
*/
23-
case BOOL_KIND = Kind::LITERAL_KIND + 1;
25+
case BOOL_KIND = LITERAL_KIND + 1;
2426

2527
/**
2628
* Denotes any {@see float} type.
2729
*/
28-
case FLOAT_KIND = Kind::LITERAL_KIND + 2;
30+
case FLOAT_KIND = LITERAL_KIND + 2;
2931

3032
/**
3133
* Denotes any {@see int} type.
3234
*/
33-
case INT_KIND = Kind::LITERAL_KIND + 3;
35+
case INT_KIND = LITERAL_KIND + 3;
3436

3537
/**
3638
* Denotes any {@see null} type.
3739
*/
38-
case NULL_KIND = Kind::LITERAL_KIND + 4;
40+
case NULL_KIND = LITERAL_KIND + 4;
3941

4042
/**
4143
* Denotes any {@see string} type.
4244
*/
43-
case STRING_KIND = Kind::LITERAL_KIND + 5;
45+
case STRING_KIND = LITERAL_KIND + 5;
4446

4547
/**
4648
* Denotes any variable (for example function
4749
* argument/parameter) type.
4850
*/
49-
case VARIABLE_KIND = Kind::LITERAL_KIND + 6;
51+
case VARIABLE_KIND = LITERAL_KIND + 6;
5052

5153
/**
5254
* @return int<0, max>

src/Node/Stmt/Condition/ConditionKind.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use TypeLang\Parser\Node\Kind;
88

9+
const CONDITION_KIND = Kind::CONDITION_KIND;
10+
911
enum ConditionKind: int implements \JsonSerializable
1012
{
1113
/**
@@ -14,17 +16,17 @@ enum ConditionKind: int implements \JsonSerializable
1416
*
1517
* @internal
1618
*/
17-
case UNKNOWN = Kind::CONDITION_KIND;
19+
case UNKNOWN = CONDITION_KIND;
1820

1921
/**
2022
* Indicates an equivalent comparison condition.
2123
*/
22-
case KIND_EQUAL = Kind::CONDITION_KIND + 1;
24+
case KIND_EQUAL = CONDITION_KIND + 1;
2325

2426
/**
2527
* Indicates an non-equivalent comparison condition.
2628
*/
27-
case KIND_NOT_EQUAL = Kind::CONDITION_KIND + 2;
29+
case KIND_NOT_EQUAL = CONDITION_KIND + 2;
2830

2931
/**
3032
* @return int<0, max>

src/Node/Stmt/Shape/ShapeFieldKind.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use TypeLang\Parser\Node\Kind;
88

9+
const SHAPE_FIELD_KIND = Kind::SHAPE_FIELD_KIND;
10+
911
enum ShapeFieldKind: int implements \JsonSerializable
1012
{
1113
/**
@@ -14,27 +16,27 @@ enum ShapeFieldKind: int implements \JsonSerializable
1416
*
1517
* @internal
1618
*/
17-
case UNKNOWN = Kind::SHAPE_FIELD_KIND;
19+
case UNKNOWN = SHAPE_FIELD_KIND;
1820

1921
/**
2022
* Defines a field with a key of the form `key`.
2123
*/
22-
case NAMED_FIELD_KIND = Kind::SHAPE_FIELD_KIND + 1;
24+
case NAMED_FIELD_KIND = SHAPE_FIELD_KIND + 1;
2325

2426
/**
2527
* Defines a field with a key of the form `"key"`.
2628
*/
27-
case STRING_FIELD_KIND = Kind::SHAPE_FIELD_KIND + 2;
29+
case STRING_FIELD_KIND = SHAPE_FIELD_KIND + 2;
2830

2931
/**
3032
* Defines a field with a key of the form `42`.
3133
*/
32-
case NUMERIC_FIELD_KIND = Kind::SHAPE_FIELD_KIND + 3;
34+
case NUMERIC_FIELD_KIND = SHAPE_FIELD_KIND + 3;
3335

3436
/**
3537
* Defines a field without key.
3638
*/
37-
case IMPLICIT_FIELD_KIND = Kind::SHAPE_FIELD_KIND + 4;
39+
case IMPLICIT_FIELD_KIND = SHAPE_FIELD_KIND + 4;
3840

3941
/**
4042
* @return int<0, max>

src/Node/Stmt/TypeKind.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use TypeLang\Parser\Node\Kind;
88

9+
const TYPE_KIND = Kind::TYPE_KIND;
10+
911
enum TypeKind: int implements \JsonSerializable
1012
{
1113
/**
@@ -14,7 +16,7 @@ enum TypeKind: int implements \JsonSerializable
1416
*
1517
* @internal
1618
*/
17-
case UNKNOWN = Kind::TYPE_KIND;
19+
case UNKNOWN = TYPE_KIND;
1820

1921
/**
2022
* Denotes any named type, which may be a reference to a class,
@@ -24,7 +26,7 @@ enum TypeKind: int implements \JsonSerializable
2426
* Path\To\SomeClass<T, Y>
2527
* ```
2628
*/
27-
case TYPE_KIND = Kind::TYPE_KIND + 1;
29+
case TYPE_KIND = TYPE_KIND + 1;
2830

2931
/**
3032
* Denotes any callable type that can contain parameters
@@ -34,7 +36,7 @@ enum TypeKind: int implements \JsonSerializable
3436
* example(T, U): V
3537
* ```
3638
*/
37-
case CALLABLE_KIND = Kind::TYPE_KIND + 2;
39+
case CALLABLE_KIND = TYPE_KIND + 2;
3840

3941
/**
4042
* Denotes a constant mask for a class.
@@ -43,7 +45,7 @@ enum TypeKind: int implements \JsonSerializable
4345
* Path\To\SomeClass::CONST_*
4446
* ```
4547
*/
46-
case CLASS_CONST_MASK_KIND = Kind::TYPE_KIND + 3;
48+
case CLASS_CONST_MASK_KIND = TYPE_KIND + 3;
4749

4850
/**
4951
* Denotes a reference to a specific class constant.
@@ -52,7 +54,7 @@ enum TypeKind: int implements \JsonSerializable
5254
* Path\To\SomeClass::CONST_NAME
5355
* ```
5456
*/
55-
case CLASS_CONST_KIND = Kind::TYPE_KIND + 4;
57+
case CLASS_CONST_KIND = TYPE_KIND + 4;
5658

5759
/**
5860
* Denotes a global constant mask.
@@ -61,7 +63,7 @@ enum TypeKind: int implements \JsonSerializable
6163
* JSON_ERROR_*
6264
* ```
6365
*/
64-
case CONST_MASK_KIND = Kind::TYPE_KIND + 5;
66+
case CONST_MASK_KIND = TYPE_KIND + 5;
6567

6668
/**
6769
* Denotes the logical intersection type.
@@ -70,7 +72,7 @@ enum TypeKind: int implements \JsonSerializable
7072
* T & U
7173
* ```
7274
*/
73-
case LOGICAL_INTERSECTION_KIND = Kind::TYPE_KIND + 6;
75+
case LOGICAL_INTERSECTION_KIND = TYPE_KIND + 6;
7476

7577
/**
7678
* Denotes the logical union type.
@@ -79,7 +81,7 @@ enum TypeKind: int implements \JsonSerializable
7981
* T | U
8082
* ```
8183
*/
82-
case LOGICAL_UNION_KIND = Kind::TYPE_KIND + 7;
84+
case LOGICAL_UNION_KIND = TYPE_KIND + 7;
8385

8486
/**
8587
* Denotes the nullable type.
@@ -88,7 +90,7 @@ enum TypeKind: int implements \JsonSerializable
8890
* ?T
8991
* ```
9092
*/
91-
case NULLABLE_KIND = Kind::TYPE_KIND + 8;
93+
case NULLABLE_KIND = TYPE_KIND + 8;
9294

9395
/**
9496
* Denotes the logical ternary type.
@@ -97,7 +99,7 @@ enum TypeKind: int implements \JsonSerializable
9799
* T ? U : V
98100
* ```
99101
*/
100-
case TERNARY_KIND = Kind::TYPE_KIND + 9;
102+
case TERNARY_KIND = TYPE_KIND + 9;
101103

102104
/**
103105
* Indicates a list type in the "legacy" syntax format.
@@ -106,7 +108,7 @@ enum TypeKind: int implements \JsonSerializable
106108
* T[]
107109
* ```
108110
*/
109-
case LIST_KIND = Kind::TYPE_KIND + 10;
111+
case LIST_KIND = TYPE_KIND + 10;
110112

111113
/**
112114
* @return int<0, max>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"kind": 263,
3+
"items": [
4+
{
5+
"kind": 257,
6+
"name": "int"
7+
},
8+
{
9+
"kind": 257,
10+
"name": "float"
11+
}
12+
]
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
O:39:"TypeLang\Parser\Node\Stmt\UnionTypeNode":2:{i:0;i:0;i:1;a:2:{i:0;O:39:"TypeLang\Parser\Node\Stmt\NamedTypeNode":4:{s:6:"offset";i:0;s:4:"name";O:25:"TypeLang\Parser\Node\Name":2:{i:0;i:0;i:1;a:1:{i:0;O:31:"TypeLang\Parser\Node\Identifier":2:{i:0;i:0;i:1;s:3:"int";}}}s:9:"arguments";N;s:6:"fields";N;}i:1;O:39:"TypeLang\Parser\Node\Stmt\NamedTypeNode":4:{s:6:"offset";i:0;s:4:"name";O:25:"TypeLang\Parser\Node\Name":2:{i:0;i:0;i:1;a:1:{i:0;O:31:"TypeLang\Parser\Node\Identifier":2:{i:0;i:0;i:1;s:5:"float";}}}s:9:"arguments";N;s:6:"fields";N;}}}

0 commit comments

Comments
 (0)