Skip to content

Commit 1ba1641

Browse files
committed
Fix more than one annotation on an element only yielding the last
1 parent 533a01d commit 1ba1641

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

ChangeLog.md

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

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

6+
## 11.7.1 / 2025-07-06
7+
8+
* Fixed more than one annotation on an element only yielding the last.
9+
(@thekid)
10+
611
## 11.7.0 / 2025-06-22
712

813
* Merged PR #56: Implement "clone with" syntax using a `CloneExpression`

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ private function properties($parse, &$body, $meta, $modifiers, $type) {
14591459
private function annotations($parse, $context) {
14601460
$annotations= new Annotations([], $parse->token->line);
14611461

1462-
while ('name' === $parse->token->kind) {
1462+
next: while ('name' === $parse->token->kind) {
14631463
$name= ltrim($parse->scope->resolve($parse->token->value), '\\');
14641464
$parse->forward();
14651465

@@ -1475,6 +1475,12 @@ private function annotations($parse, $context) {
14751475
}
14761476
$parse->expecting(']', $context);
14771477

1478+
// Check if another annotation follows
1479+
if ('#[' === $parse->token->value) {
1480+
$parse->forward();
1481+
goto next;
1482+
}
1483+
14781484
return $annotations;
14791485
}
14801486

src/test/php/lang/ast/unittest/parse/AttributesTest.class.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ class T { }
110110
'));
111111
}
112112

113+
#[Test, Values(['#[Runtime, Service]', '#[Runtime] #[Service]'])]
114+
public function multiple_annotations($declaration) {
115+
$this->assertAnnotated(['Runtime' => [], 'Service' => []], $this->type($declaration.' class T { }'));
116+
}
117+
113118
#[Test]
114119
public function after_oneline_comment() {
115120
$this->assertAnnotated(['Service' => []], $this->type('

0 commit comments

Comments
 (0)