Skip to content

Commit

Permalink
Fix grouped use statements containing aliases not scoped correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Aug 11, 2024
1 parent 7bfc6d4 commit e19b092
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>::class` - @thekid
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/lang/ast/syntax/PHP.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/test/php/lang/ast/unittest/parse/NamespacesTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/test/php/lang/ast/unittest/parse/ParseTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use test\Assert;

abstract class ParseTest {
const LINE = 1;
const LINE= 1;

/**
* Parse code, returning nodes on at a time
Expand Down

0 comments on commit e19b092

Please sign in to comment.