From 198ffa79e93a21c6c1a5894fd2b5153e5184bb23 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Tue, 28 Nov 2023 14:15:16 +0100 Subject: [PATCH] Fix NameResolver for class constant native type --- lib/PhpParser/NodeVisitor/NameResolver.php | 3 +++ test/PhpParser/NodeVisitor/NameResolverTest.php | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/PhpParser/NodeVisitor/NameResolver.php b/lib/PhpParser/NodeVisitor/NameResolver.php index 3618fb9f8f..ccd014ebbd 100644 --- a/lib/PhpParser/NodeVisitor/NameResolver.php +++ b/lib/PhpParser/NodeVisitor/NameResolver.php @@ -115,6 +115,9 @@ public function enterNode(Node $node) { $this->addNamespacedName($const); } } elseif ($node instanceof Stmt\ClassConst) { + if (null !== $node->type) { + $node->type = $this->resolveType($node->type); + } $this->resolveAttrGroups($node); } elseif ($node instanceof Stmt\EnumCase) { $this->resolveAttrGroups($node); diff --git a/test/PhpParser/NodeVisitor/NameResolverTest.php b/test/PhpParser/NodeVisitor/NameResolverTest.php index d38a90c826..b0065968c7 100644 --- a/test/PhpParser/NodeVisitor/NameResolverTest.php +++ b/test/PhpParser/NodeVisitor/NameResolverTest.php @@ -188,7 +188,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; @@ -197,6 +197,10 @@ class A extends B implements C, D { #[X] const C = 1; + + public const X A = X::Bar; + public const X\Foo B = X\Foo::Bar; + public const \X\Foo C = \X\Foo::Bar; } #[X] @@ -262,6 +266,9 @@ class A extends \NS\B implements \NS\C, \NS\D public \NS\A|\NS\B|int $prop; #[\NS\X] const C = 1; + public const \NS\X A = \NS\X::Bar; + public const \NS\X\Foo B = \NS\X\Foo::Bar; + public const \X\Foo C = \X\Foo::Bar; } #[\NS\X] interface A extends \NS\C, \NS\D