Skip to content

Commit

Permalink
Fix resolving namespace keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Apr 3, 2022
1 parent e07d4db commit 0c2ac3e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ XP AST ChangeLog

## ?.?.? / ????-??-??

## 8.0.1 / 2022-04-03

* Fixed resolving types starting with `namespace` keyword (examples 4 and
5 in https://www.php.net/manual/en/language.namespaces.nsconstants.php)
(@thekid)

## 8.0.0 / 2022-01-07

This major release promotes annotations and comments to *Node* subclasses,
Expand Down
2 changes: 2 additions & 0 deletions src/main/php/lang/ast/Scope.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public function resolve($name) {
return $name;
} else if (isset($this->imports[$name])) {
return $this->imports[$name];
} else if (0 === strncmp($name, 'namespace\\', 10)) {
return $this->package.'\\'.substr($name, 10);
} else if ($this->package) {
return $this->package.'\\'.$name;
} else if ($this->parent) {
Expand Down
15 changes: 15 additions & 0 deletions src/test/php/lang/ast/unittest/ScopeTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,19 @@ public function resolve_global() {
Assert::equals('\\Traversable', $s->resolve('Traversable'));
}

#[Test]
public function resolve_namespace_keyword() {
$s= new Scope();
$s->package('test');

Assert::equals('\\test\\Date', $s->resolve('namespace\\Date'));
}

#[Test]
public function resolve_sub_namespace() {
$s= new Scope();
$s->package('test');

Assert::equals('\\test\\util\\Date', $s->resolve('namespace\\util\\Date'));
}
}

0 comments on commit 0c2ac3e

Please sign in to comment.