Skip to content

Commit 715a2c8

Browse files
committed
Fix parsing $offset[yield] ?? null
1 parent 5007953 commit 715a2c8

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ XP AST ChangeLog
33

44
## ?.?.? / ????-??-??
55

6+
## 12.2.1 / 2026-06-26
7+
8+
* Fixed parsing `$offset[yield] ?? null` - @thekid
9+
610
## 12.2.0 / 2026-05-23
711

812
* Merged PR #61: Refactor function scopes: Capturing and returning.

src/main/php/lang/ast/syntax/PHP.class.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -373,18 +373,16 @@ public function __construct() {
373373
if ('from' === $parse->token->value) {
374374
$parse->forward();
375375
return new YieldFromExpression($this->expression($parse, 0), $token->line);
376+
} else if ('operator' === $parse->token->kind && '(' !== $parse->token->value) {
377+
return new YieldExpression(null, null, $token->line);
378+
}
379+
380+
$expr= $this->expression($parse, 0);
381+
if ('=>' === $parse->token->value) {
382+
$parse->forward();
383+
return new YieldExpression($expr, $this->expression($parse, 0), $token->line);
376384
} else {
377-
$expr= $this->expression($parse, 0);
378-
if ('operator' === $expr->kind) {
379-
array_unshift($parse->queue, $parse->token);
380-
$parse->token= $expr;
381-
return new YieldExpression(null, null, $token->line);
382-
} else if ('=>' === $parse->token->value) {
383-
$parse->forward();
384-
return new YieldExpression($expr, $this->expression($parse, 0), $token->line);
385-
} else {
386-
return new YieldExpression(null, $expr, $token->line);
387-
}
385+
return new YieldExpression(null, $expr, $token->line);
388386
}
389387
});
390388

0 commit comments

Comments
 (0)