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

[Php81] Skip param variable used in next stmt after coalesce on NewInInitializerRector #5971

Merged
merged 2 commits into from
Jun 14, 2024

Conversation

samsonasik
Copy link
Member

@samsonasik
Copy link
Member Author

Fixed 🎉 /cc @VincentLanglet

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba I am merging it ;)

@samsonasik samsonasik merged commit 04e662e into main Jun 14, 2024
39 checks passed
@samsonasik samsonasik deleted the skip-usd-next branch June 14, 2024 13:55
@@ -112,6 +119,10 @@ public function refactor(Node $node): ?Node
continue;
}

if ($this->stmtsManipulator->isVariableUsedInNextStmt($stmts, $key + 1, $paramName)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with rector code, so what does nextstmt means ? @samsonasik

Does it also fix the bug for code like

public function __construct(?\DateTime $time = null)
    {
        $this->timeWasSet = null !== $time; // Here the statement is before 
        $this->time = $time ?? new \DateTime();
    }

or

public function __construct(?\DateTime $time = null)
    {
        $this->time = $time ?? new \DateTime();

        // Some code...

        $a = random_int(0, 1);
        if ($a === 1) {
            $this->timeWasSet = null !== $time; // Here it's not the direct next statement
        }
    }

Copy link
Member Author

@samsonasik samsonasik Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That mean variable used by next stmt start by key + 1 until end of stmts.

Yes, that should cover that, feel free to try latest dev-main

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 this pull request may close these issues.

Incorrect behavior of NewInInitializerRector
2 participants