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

$this incorrectly detected inside object creation expression #2618

Closed
przepompownia opened this issue Mar 27, 2024 · 6 comments
Closed

$this incorrectly detected inside object creation expression #2618

przepompownia opened this issue Mar 27, 2024 · 6 comments

Comments

@przepompownia
Copy link
Contributor

image

The case

        return new Success((function () {
            $classes = $this;
        })());

exists for example in lib/CodeTransform/Adapter/WorseReflection/Transformer/ImplementContracts.php.

It's a regression after #2469 @mamazu

Perhaps similar caution will be needed in #2613

@mamazu
Copy link
Contributor

mamazu commented Mar 27, 2024

Could you maybe come up with a test case for that and I'll have a look at it.

@przepompownia
Copy link
Contributor Author

przepompownia commented Mar 27, 2024

#2619 - there is only test

@przepompownia
Copy link
Contributor Author

I also looked into FunctionLikeWalker but don't have idea how to distinguish whether created object belongs to named or anonymous class.

@mamazu
Copy link
Contributor

mamazu commented Mar 28, 2024

The distinguishing feature is that the typeDescrimitator of the ObjectCreationExpression is a Token and not a Node. That's what we are using in the other PR.

@mamazu
Copy link
Contributor

mamazu commented Mar 28, 2024

I've created a fix pr: #2620

I still hold the opinion that the Parser should return a more coherent structure but oh well.

@przepompownia
Copy link
Contributor Author

Fixed by #2620

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

Successfully merging a pull request may close this issue.

2 participants