diff --git a/lib/PhpParser/NodeVisitor/NameResolver.php b/lib/PhpParser/NodeVisitor/NameResolver.php index d0e7de02f5..83f3ea831c 100644 --- a/lib/PhpParser/NodeVisitor/NameResolver.php +++ b/lib/PhpParser/NodeVisitor/NameResolver.php @@ -118,6 +118,9 @@ public function enterNode(Node $node) { $this->addNamespacedName($const); } } else if ($node instanceof Stmt\ClassConst) { + if (null !== $node->type) { + $node->type = $this->resolveType($node->type); + } $this->resolveAttrGroups($node); } else if ($node instanceof Stmt\EnumCase) { $this->resolveAttrGroups($node); diff --git a/test/PhpParser/NodeVisitor/NameResolverTest.php b/test/PhpParser/NodeVisitor/NameResolverTest.php index b5035ce3fe..db5b40a247 100644 --- a/test/PhpParser/NodeVisitor/NameResolverTest.php +++ b/test/PhpParser/NodeVisitor/NameResolverTest.php @@ -189,7 +189,7 @@ class A extends B implements C, D { E::h as i; E::j insteadof F, G; } - + #[X] public float $php = 7.4; public ?Foo $person; @@ -537,6 +537,27 @@ public function testAttributeOnlyMode() { new Name\FullyQualified('Foo\bar'), $n2->getAttribute('namespacedName')); } + public function testClassConstantNativeType() { + $source = <<<'EOC' +parseAndResolve($source); + $classStmt = $stmts[0]->stmts[0]; + + $this->assertSame('Foo\\X', (string) $classStmt->stmts[0]->type); + $this->assertSame('Foo\\X\\Foo', (string) $classStmt->stmts[1]->type); + $this->assertSame('X\\Foo', (string) $classStmt->stmts[2]->type); + } + private function parseAndResolve(string $code): array { $parser = new PhpParser\Parser\Php7(new PhpParser\Lexer\Emulative);