Skip to content

Commit 1d660cc

Browse files
committed
Tokenizer/PHP: readonly vs union types bug fix
Done some more stress testing and found that the retokenization of `|` to `T_TYPE_UNION` was broken when combined with the `readonly` keyword. Fixed now, includes test.
1 parent 6296b27 commit 1d660cc

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

src/Tokenizers/PHP.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2710,7 +2710,8 @@ protected function processAdditional()
27102710

27112711
if ($suspectedType === 'property or parameter'
27122712
&& (isset(Util\Tokens::$scopeModifiers[$this->tokens[$x]['code']]) === true
2713-
|| $this->tokens[$x]['code'] === T_VAR)
2713+
|| $this->tokens[$x]['code'] === T_VAR
2714+
|| $this->tokens[$x]['code'] === T_READONLY)
27142715
) {
27152716
// This will also confirm constructor property promotion parameters, but that's fine.
27162717
$confirmed = true;

tests/Core/Tokenizer/BitwiseOrTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class TypeUnion
3333
/* testTypeUnionPropertyFullyQualified */
3434
public \Fully\Qualified\NameA|\Fully\Qualified\NameB $fullyQual;
3535

36+
/* testTypeUnionPropertyWithReadOnlyKeyword */
37+
protected readonly string|null $array;
38+
3639
public function paramTypes(
3740
/* testTypeUnionParam1 */
3841
int|float $paramA /* testBitwiseOrParamDefaultValue */ = CONSTANT_A | CONSTANT_B,

tests/Core/Tokenizer/BitwiseOrTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function dataTypeUnion()
105105
['/* testTypeUnionPropertyNamespaceRelative */'],
106106
['/* testTypeUnionPropertyPartiallyQualified */'],
107107
['/* testTypeUnionPropertyFullyQualified */'],
108+
['/* testTypeUnionPropertyWithReadOnlyKeyword */'],
108109
['/* testTypeUnionParam1 */'],
109110
['/* testTypeUnionParam2 */'],
110111
['/* testTypeUnionParam3 */'],

0 commit comments

Comments
 (0)