Skip to content

Commit e0d0880

Browse files
committed
Fix regression after supporting intersection types
checkToken only supports an integer, but started getting passed an array after supporting intersection types (`['|', '&']`). Fix a few other type signatures
1 parent 6a96561 commit e0d0880

File tree

5 files changed

+111
-5
lines changed

5 files changed

+111
-5
lines changed

src/Node/Expression/YieldExpression.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class YieldExpression extends Expression {
1414
/** @var Token */
1515
public $yieldOrYieldFromKeyword;
1616

17-
/** @var ArrayElement */
17+
/** @var ArrayElement|null */
1818
public $arrayElement;
1919

2020
const CHILD_NAMES = ['yieldOrYieldFromKeyword', 'arrayElement'];

src/Parser.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ private function parseParameterFn() {
839839
array_pop($parameter->typeDeclarationList->children);
840840
$parameter->byRefToken = array_pop($parameter->typeDeclarationList->children);
841841
if (!$parameter->typeDeclarationList->children) {
842-
unset($parameter->typeDeclarationList);
842+
$parameter->typeDeclarationList = null;
843843
}
844844
}
845845
} elseif ($parameter->questionToken) {
@@ -1546,7 +1546,7 @@ private function isParameterStartFn() {
15461546

15471547
/**
15481548
* @param string $className (name of subclass of DelimitedList)
1549-
* @param int $delimiter
1549+
* @param int|int[] $delimiter
15501550
* @param callable $isElementStartFn
15511551
* @param callable $parseElementFn
15521552
* @param Node $parentNode
@@ -1560,7 +1560,7 @@ private function parseDelimitedList($className, $delimiter, $isElementStartFn, $
15601560
do {
15611561
if ($isElementStartFn($token)) {
15621562
$node->addElement($parseElementFn($node));
1563-
} elseif (!$allowEmptyElements || ($allowEmptyElements && !$this->checkToken($delimiter))) {
1563+
} elseif (!$allowEmptyElements || ($allowEmptyElements && !$this->checkAnyToken($delimiter))) {
15641564
break;
15651565
}
15661566

@@ -1572,7 +1572,6 @@ private function parseDelimitedList($className, $delimiter, $isElementStartFn, $
15721572
// TODO ERROR CASE - no delimiter, but a param follows
15731573
} while ($delimiterToken !== null);
15741574

1575-
15761575
$node->parent = $parentNode;
15771576
if ($node->children === null) {
15781577
return null;
@@ -1772,10 +1771,17 @@ private function lookahead(...$expectedKinds) : bool {
17721771
return $succeeded;
17731772
}
17741773

1774+
/** @param int $expectedKind */
17751775
private function checkToken($expectedKind) : bool {
17761776
return $this->getCurrentToken()->kind === $expectedKind;
17771777
}
17781778

1779+
/** @param int|int[] $expectedKind */
1780+
private function checkAnyToken($expectedKind) : bool {
1781+
$kind = $this->getCurrentToken()->kind;
1782+
return \is_array($expectedKind) ? \in_array($kind, $expectedKind, true) : $kind === $expectedKind;
1783+
}
1784+
17791785
private function parseIfStatement($parentNode) {
17801786
$ifStatement = new IfStatementNode();
17811787
$ifStatement->parent = $parentNode;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
class X {
3+
public |string $var;
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
"ClassDeclaration": {
16+
"attributes": null,
17+
"abstractOrFinalModifier": null,
18+
"classKeyword": {
19+
"kind": "ClassKeyword",
20+
"textLength": 5
21+
},
22+
"name": {
23+
"kind": "Name",
24+
"textLength": 1
25+
},
26+
"classBaseClause": null,
27+
"classInterfaceClause": null,
28+
"classMembers": {
29+
"ClassMembersNode": {
30+
"openBrace": {
31+
"kind": "OpenBraceToken",
32+
"textLength": 1
33+
},
34+
"classMemberDeclarations": [
35+
{
36+
"PropertyDeclaration": {
37+
"attributes": null,
38+
"modifiers": [
39+
{
40+
"kind": "PublicKeyword",
41+
"textLength": 6
42+
}
43+
],
44+
"questionToken": null,
45+
"typeDeclarationList": {
46+
"QualifiedNameList": {
47+
"children": [
48+
{
49+
"kind": "BarToken",
50+
"textLength": 1
51+
},
52+
{
53+
"kind": "StringReservedWord",
54+
"textLength": 6
55+
}
56+
]
57+
}
58+
},
59+
"propertyElements": {
60+
"ExpressionList": {
61+
"children": [
62+
{
63+
"Variable": {
64+
"dollar": null,
65+
"name": {
66+
"kind": "VariableName",
67+
"textLength": 4
68+
}
69+
}
70+
}
71+
]
72+
}
73+
},
74+
"semicolon": {
75+
"kind": "SemicolonToken",
76+
"textLength": 1
77+
}
78+
}
79+
}
80+
],
81+
"closeBrace": {
82+
"kind": "CloseBraceToken",
83+
"textLength": 1
84+
}
85+
}
86+
}
87+
}
88+
}
89+
],
90+
"endOfFileToken": {
91+
"kind": "EndOfFileToken",
92+
"textLength": 0
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)