From e19b0920ccce9d2284713498221519bf5c3a3373 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 11 Aug 2024 23:43:20 +0200 Subject: [PATCH] Fix grouped `use` statements containing aliases not scoped correctly --- ChangeLog.md | 3 +++ src/main/php/lang/ast/syntax/PHP.class.php | 2 +- .../php/lang/ast/unittest/parse/NamespacesTest.class.php | 8 ++++++++ src/test/php/lang/ast/unittest/parse/ParseTest.class.php | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index e25e7ee..01cd614 100755 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,6 +3,9 @@ XP AST ChangeLog ## ?.?.? / ????-??-?? +* Fixed grouped `use` statements containing aliases not scoped correctly + (@thekid) + ## 11.2.0 / 2024-08-04 * Merged PR #53: Add syntactic support for `T::class` - @thekid diff --git a/src/main/php/lang/ast/syntax/PHP.class.php b/src/main/php/lang/ast/syntax/PHP.class.php index 817cd3c..59cb96f 100755 --- a/src/main/php/lang/ast/syntax/PHP.class.php +++ b/src/main/php/lang/ast/syntax/PHP.class.php @@ -619,7 +619,7 @@ public function __construct() { if ('as' === $parse->token->value) { $parse->forward(); $names[$class]= $parse->token->value; - $parse->scope->import($parse->token->value); + $parse->scope->import($class, $parse->token->value); $parse->forward(); } else { $names[$class]= null; diff --git a/src/test/php/lang/ast/unittest/parse/NamespacesTest.class.php b/src/test/php/lang/ast/unittest/parse/NamespacesTest.class.php index 0266cfd..ea088cc 100755 --- a/src/test/php/lang/ast/unittest/parse/NamespacesTest.class.php +++ b/src/test/php/lang/ast/unittest/parse/NamespacesTest.class.php @@ -37,6 +37,14 @@ public function use_with_alias() { ); } + #[Test] + public function use_with_alias_in_group() { + $this->assertParsed( + [new UseStatement(null, ['lang\ast\Type' => null, 'lang\ast\Parse' => 'P'], self::LINE)], + 'use lang\\ast\\{Type, Parse as P};' + ); + } + #[Test] public function use_with_types_separated_by_commas() { $this->assertParsed( diff --git a/src/test/php/lang/ast/unittest/parse/ParseTest.class.php b/src/test/php/lang/ast/unittest/parse/ParseTest.class.php index bde4c63..8a26fa8 100755 --- a/src/test/php/lang/ast/unittest/parse/ParseTest.class.php +++ b/src/test/php/lang/ast/unittest/parse/ParseTest.class.php @@ -5,7 +5,7 @@ use test\Assert; abstract class ParseTest { - const LINE = 1; + const LINE= 1; /** * Parse code, returning nodes on at a time