Skip to content

Commit a38e03b

Browse files
authored
Merge pull request microsoft#350 from dantleech/mixed-reserved-word
Add support for PHP 8.0 mixed type
2 parents f2ec9ea + e5ebee7 commit a38e03b

File tree

8 files changed

+107
-7
lines changed

8 files changed

+107
-7
lines changed

phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ parameters:
55
ignoreErrors:
66
# phpstan issue, see: https://github.com/phpstan/phpstan/issues/1306
77
- "/Variable .unaryExpression might not be defined./"
8-
- "/Variable .prefix might not be defined./"

src/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function __construct() {
142142
[TokenKind::ArrayKeyword, TokenKind::CallableKeyword, TokenKind::BoolReservedWord,
143143
TokenKind::FloatReservedWord, TokenKind::IntReservedWord, TokenKind::StringReservedWord,
144144
TokenKind::ObjectReservedWord, TokenKind::NullReservedWord, TokenKind::FalseReservedWord,
145-
TokenKind::IterableKeyword]; // TODO update spec
145+
TokenKind::IterableReservedWord, TokenKind::MixedReservedWord]; // TODO update spec
146146
$this->returnTypeDeclarationTokens = \array_merge([TokenKind::VoidReservedWord, TokenKind::NullReservedWord, TokenKind::FalseReservedWord, TokenKind::StaticKeyword], $this->parameterTypeDeclarationTokens);
147147
}
148148

src/TokenKind.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ class TokenKind {
8787
const YieldFromKeyword = 167;
8888
const FnKeyword = 168;
8989
const MatchKeyword = 169;
90-
const IterableKeyword = 170;
90+
/** @deprecated use IterableReservedWord */
91+
const IterableKeyword = self::IterableReservedWord;
9192

9293
const OpenBracketToken = 201;
9394
const CloseBracketToken = 202;
@@ -170,6 +171,8 @@ class TokenKind {
170171
const StringReservedWord = 320;
171172
const BoolReservedWord = 321;
172173
const NullReservedWord = 322;
174+
const MixedReservedWord = 340;
175+
const IterableReservedWord = 170;
173176

174177
const ScriptSectionStartTag = 323;
175178
const ScriptSectionEndTag = 324;

src/TokenStringMaps.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ class TokenStringMaps {
104104
"object" => TokenKind::ObjectReservedWord,
105105
"real" => TokenKind::RealReservedWord,
106106
"void" => TokenKind::VoidReservedWord,
107-
"iterable" => TokenKind::IterableKeyword,
107+
"iterable" => TokenKind::IterableReservedWord,
108+
"mixed" => TokenKind::MixedReservedWord,
108109
];
109110

110111
const OPERATORS_AND_PUNCTUATORS = array(

tests/cases/parser74/arrowFunctionUnionTypes.php.tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
"visibilityToken": null,
242242
"questionToken": null,
243243
"typeDeclaration": {
244-
"kind": "IterableKeyword",
244+
"kind": "IterableReservedWord",
245245
"textLength": 8
246246
},
247247
"otherTypeDeclarations": {
@@ -398,7 +398,7 @@
398398
"visibilityToken": null,
399399
"questionToken": null,
400400
"typeDeclaration": {
401-
"kind": "IterableKeyword",
401+
"kind": "IterableReservedWord",
402402
"textLength": 8
403403
},
404404
"otherTypeDeclarations": {
@@ -573,7 +573,7 @@
573573
"textLength": 1
574574
},
575575
{
576-
"kind": "IterableKeyword",
576+
"kind": "IterableReservedWord",
577577
"textLength": 8
578578
}
579579
]

tests/cases/parser80/mixedType1.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
function foobar(mixed $bar): mixed
4+
{
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
"FunctionDeclaration": {
16+
"attributes": null,
17+
"functionKeyword": {
18+
"kind": "FunctionKeyword",
19+
"textLength": 8
20+
},
21+
"byRefToken": null,
22+
"name": {
23+
"kind": "Name",
24+
"textLength": 6
25+
},
26+
"openParen": {
27+
"kind": "OpenParenToken",
28+
"textLength": 1
29+
},
30+
"parameters": {
31+
"ParameterDeclarationList": {
32+
"children": [
33+
{
34+
"Parameter": {
35+
"attributes": null,
36+
"visibilityToken": null,
37+
"questionToken": null,
38+
"typeDeclaration": {
39+
"kind": "MixedReservedWord",
40+
"textLength": 5
41+
},
42+
"otherTypeDeclarations": null,
43+
"byRefToken": null,
44+
"dotDotDotToken": null,
45+
"variableName": {
46+
"kind": "VariableName",
47+
"textLength": 4
48+
},
49+
"equalsToken": null,
50+
"default": null
51+
}
52+
}
53+
]
54+
}
55+
},
56+
"closeParen": {
57+
"kind": "CloseParenToken",
58+
"textLength": 1
59+
},
60+
"colonToken": {
61+
"kind": "ColonToken",
62+
"textLength": 1
63+
},
64+
"questionToken": null,
65+
"returnType": {
66+
"kind": "MixedReservedWord",
67+
"textLength": 5
68+
},
69+
"otherReturnTypes": null,
70+
"compoundStatementOrSemicolon": {
71+
"CompoundStatementNode": {
72+
"openBrace": {
73+
"kind": "OpenBraceToken",
74+
"textLength": 1
75+
},
76+
"statements": [],
77+
"closeBrace": {
78+
"kind": "CloseBraceToken",
79+
"textLength": 1
80+
}
81+
}
82+
}
83+
}
84+
}
85+
],
86+
"endOfFileToken": {
87+
"kind": "EndOfFileToken",
88+
"textLength": 0
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)