Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is QualifiedName::getResolvedName disabled for Node\TraitUseClause? #400

Open
zobo opened this issue May 15, 2023 · 4 comments
Open

Comments

@zobo
Copy link
Contributor

zobo commented May 15, 2023

When I need to resolve the FQN of the use TestTrait I cannot use the handy getResolvedName. Why is that?

namespace YYY;

use \XXX\TestTrait;

class TestClazz
{
	use TestTrait;

https://github.com/microsoft/tolerant-php-parser/blame/84ce745a39619b10734c8e6b736e055b9fa64d13/src/Node/QualifiedName.php#L88

Thanks!

@roblourens
Copy link
Member

I don't know- I was just looking at the test cases and I'm not sure why you can use it on some code that references that name, but not in the use statement. If it makes sense, we could change that.

@zobo
Copy link
Contributor Author

zobo commented May 15, 2023

Hi, thanks for the feedback. Maybe it has something to do with the crazy things you can do with the insteadof and as keywords. See "Conflict resolution" in https://www.php.net/manual/en/language.oop5.traits.php .

@zobo
Copy link
Contributor Author

zobo commented May 15, 2023

But then again, I can't imagine this be the reason... I tried commenting out Node\TraitUseClause to see if any of the tests in php-intellisense break and there was no problem - if something, some things I missed got fixed.

    public function getResolvedName($namespaceDefinition = null) {
        // Name resolution not applicable to constructs that define symbol names or aliases.
        if (($this->parent instanceof Node\Statement\NamespaceDefinition && $this->parent->name->getStartPosition() === $this->getStartPosition()) ||
            $this->parent instanceof Node\Statement\NamespaceUseDeclaration ||
            $this->parent instanceof Node\NamespaceUseClause ||
            $this->parent instanceof Node\NamespaceUseGroupClause ||
            /*$this->parent->parent instanceof Node\TraitUseClause ||*/
            $this->parent instanceof Node\TraitSelectOrAliasClause
        ) {
            return null;
        }

I have not yet managed to wrap my head around TraitSelectOrAliasClause where in the parsers it's being used.

@zobo
Copy link
Contributor Author

zobo commented May 16, 2023

I cannot figure out why @mousetraps prohibited this. use Trait works much the same way as use Namespace - in the sense of resolving to FQN.

Even the other case of TraitSelectOrAliasClause is useless here because the following code

class TestClazz
{
	use TestTrait {
		TestTrait::test2 as testX;
	}

Gets constructed into: TraitUseClause -> TratSelectOrAliasClauseList -> TraitSelectOrAliasClause -> ScopedPropertyAccessExpression -> QualifiedName.

And such $this->parent instanceof Node\TraitSelectOrAliasClause should actually be $this->parent->parent instanceof Node\TraitSelectOrAliasClause to have any effect.

Then again it still does not make sense to have this as even here the QualifiedName can be resolved without any extra logic or context.

(unless I'm missing something)

Making a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants