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

Incorrect behavior of RemoveDoubleAssignRector #8515

Closed
max4logist opened this issue Mar 1, 2024 · 3 comments
Closed

Incorrect behavior of RemoveDoubleAssignRector #8515

max4logist opened this issue Mar 1, 2024 · 3 comments
Labels

Comments

@max4logist
Copy link

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/599f1d9f-535d-446b-ab8c-b909854be398

<?php

$a = null; // This is 'A'
$b = null; // This is 'B'
$b = true;

Responsible rules

  • RemoveDoubleAssignRector

Expected Behavior

Not sure about expected behavior, but first comment must be without changes.
Second comment may be deleted, transferred to next line, or stay without changes

<?php

$a = null; // This is 'A'
$b = true; // This is 'B'

Or maybe

<?php

$a = null; // This is 'A'
// This is 'B'
$b = true; 

Current Behavior

<?php

$a = null; // This is 'B'
$b = true;
@max4logist max4logist added the bug label Mar 1, 2024
@samsonasik
Copy link
Member

that's expected, comment is belong to next stmt, see nikic/PHP-Parser#950

@max4logist
Copy link
Author

@samsonasik But why this is valid behaviour, if this code

$isFoo = false; // Deprecated value: Don't use it in future
$c = 2 * M_PI * $r; // This is the circumference
$c = 0;

was processed to

$isFoo = false; // This is the circumference
$c = 0;

This breaks comments, not just from the line being deleted

@samsonasik
Copy link
Member

Because the last stmt is the stmt that not removed, so it brings comment from previous line.

It can't be handled on rector, rather on php-parser side.

@rectorphp rectorphp locked as off-topic and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants