From c44d821c8d90cb14268ad28e8b25a46117d45e0a Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 2 Aug 2026 11:45:16 +0200 Subject: [PATCH 1/3] Emit PHP 8 attributes alongside XP meta information --- .../php/lang/ast/emit/php/XpMeta.class.php | 8 -------- .../unittest/emit/AnnotationsTest.class.php | 20 +++++++++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/php/lang/ast/emit/php/XpMeta.class.php b/src/main/php/lang/ast/emit/php/XpMeta.class.php index d34de7e7..84c4a7ea 100755 --- a/src/main/php/lang/ast/emit/php/XpMeta.class.php +++ b/src/main/php/lang/ast/emit/php/XpMeta.class.php @@ -102,12 +102,4 @@ protected function emitMeta($result, $type, $annotations, $comment) { protected function emitComment($result, $comment) { // Omit from generated code } - - protected function emitAnnotation($result, $annotation) { - // Omit from generated code - } - - protected function emitAnnotations($result, $annotations) { - // Omit from generated code - } } \ No newline at end of file diff --git a/src/test/php/lang/ast/unittest/emit/AnnotationsTest.class.php b/src/test/php/lang/ast/unittest/emit/AnnotationsTest.class.php index dfea94ce..b26d7335 100755 --- a/src/test/php/lang/ast/unittest/emit/AnnotationsTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/AnnotationsTest.class.php @@ -1,6 +1,8 @@ []]]; + yield ['#[Test("a")]', ['Test' => ['a']]]; + yield ['#[Test(1, 2, 3)]', ['Test' => [1, 2, 3]]]; + yield ['#[Test(value: "a")]', ['Test' => ['value' => 'a']]]; + } + + #[Test, Values(from: 'declarations')] + public function also_emits_php_attributes($declaration, $expected) { + $type= $this->declare($declaration); + $declared= []; + foreach ((new ReflectionClass($type->literal()))->getAttributes() as $attribute) { + $declared[$attribute->name]= $attribute->getArguments(); + } + + Assert::equals($expected, $declared); + } } \ No newline at end of file From 40a195d3ed037ce3981d1b7df494b2efe915b053 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 2 Aug 2026 11:49:30 +0200 Subject: [PATCH 2/3] Fix PHP < 8.4 --- src/test/php/lang/ast/unittest/emit/AnnotationsTest.class.php | 2 +- src/test/php/lang/ast/unittest/emit/AttributesTest.class.php | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/test/php/lang/ast/unittest/emit/AnnotationsTest.class.php b/src/test/php/lang/ast/unittest/emit/AnnotationsTest.class.php index b26d7335..1c5b6ff4 100755 --- a/src/test/php/lang/ast/unittest/emit/AnnotationsTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/AnnotationsTest.class.php @@ -28,7 +28,7 @@ public function also_emits_php_attributes($declaration, $expected) { $type= $this->declare($declaration); $declared= []; foreach ((new ReflectionClass($type->literal()))->getAttributes() as $attribute) { - $declared[$attribute->name]= $attribute->getArguments(); + $declared[$attribute->getName()]= $attribute->getArguments(); } Assert::equals($expected, $declared); diff --git a/src/test/php/lang/ast/unittest/emit/AttributesTest.class.php b/src/test/php/lang/ast/unittest/emit/AttributesTest.class.php index c395d437..894c2f85 100755 --- a/src/test/php/lang/ast/unittest/emit/AttributesTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/AttributesTest.class.php @@ -1,7 +1,5 @@ Date: Sun, 2 Aug 2026 11:53:26 +0200 Subject: [PATCH 3/3] Only run also_emits_php_attributes() in PHP 8+ --- src/test/php/lang/ast/unittest/emit/AnnotationsTest.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/php/lang/ast/unittest/emit/AnnotationsTest.class.php b/src/test/php/lang/ast/unittest/emit/AnnotationsTest.class.php index 1c5b6ff4..fcbf55d4 100755 --- a/src/test/php/lang/ast/unittest/emit/AnnotationsTest.class.php +++ b/src/test/php/lang/ast/unittest/emit/AnnotationsTest.class.php @@ -2,6 +2,7 @@ use ReflectionClass; use lang\ast\emit\php\XpMeta; +use test\verify\Runtime; use test\{Assert, Test, Values}; /** @@ -23,7 +24,7 @@ private function declarations() { yield ['#[Test(value: "a")]', ['Test' => ['value' => 'a']]]; } - #[Test, Values(from: 'declarations')] + #[Test, Runtime(php: '>=8.0.0-dev'), Values(from: 'declarations')] public function also_emits_php_attributes($declaration, $expected) { $type= $this->declare($declaration); $declared= [];