-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rename refactoring doesn't take super parameters into account #52305
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
Comments
I just ran into this as well |
Renaming the class field change both Base and Sub class parameters |
As stated above, I do think this is done today (just tested and it renamed everything so I might have missed something in your request). Can you clarify if there is anything in your request that is not handled yet @bwilkerson? |
I found problems when making the class Base {
Base({required this.value});
Base(this.value);
final int value;
}
class Sub extends Base {
Sub(super.value);
} Should become something like this: class Base {
Base({required int value}) : _value = value;
Base(this._value);
final int _value;
}
class Sub extends Base {
Sub(int value) : super(value);
} But for some weird reason, I tested with: class A {
final int foo;
A({required this.foo});
A.other(this.foo);
}
class B extends A {
B({required super.foo});
B.other(super.foo) : super.other();
}
void foo() {
A(foo: 1);
B(foo: 2);
var b = B.other(3);
print(b._foo);
} And renaming class A {
final int _foo;
A({required int foo}) : _foo = foo;
A.other(this._foo);
}
class B extends A {
B({required super.foo});
B.other(super.foo) : super.other();
}
void foo() {
A(foo: 1);
B(foo: 2);
var b = B.other(3);
print(b._foo);
} Although I can't seem to understand where is But when renaming at class A {
final int _foo;
A({required this._foo}); // <-- private_optional_parameter
A.other(this._foo);
}
class B extends A {
B({required super.foo}); // <-- super_formal_parameter_without_associated_named
B.other(super.foo) : super.other();
}
void foo() {
A(foo: 1); // <-- undefined_named_parameter
B(foo: 2);
var b = B.other(3);
print(b._foo);
} But when I rename at class A {
final int _foo;
A({required this._foo}); // < -- private_optional_parameter
A.other(this._foo);
}
class B extends A {
B({required super._foo});
B.other(super.foo) : super.other();
}
void foo() {
A(_foo: 1); // <-- different from the above where this didn't get renamed
B(foo: 2); // <-- undefined_named_parameter (issue https://github.com/dart-lang/sdk/issues/54645)
var b = B.other(3);
print(b._foo);
} So it seems some logic is missing here for everywhere to work the same way. One last thought here. When renaming at Why doesn't it simply follow the working behaviour as above since |
Here is the CL. Added you, @bwilkerson, as a reviewer https://dart-review.googlesource.com/c/sdk/+/413340. |
With the lint `` enabled, it would be nice if super parameters that have the same name as the corresponding parameter in the super-constructor were renamed when the super-constructor's parameter is renamed (whether directly or by renaming a field in the case of a field formal parameter).
For example, given
It would be nice for
super.value
to be renamed if the fieldvalue
is renamed.Depending on the outcome of #59104, we might also want to rename the super parameter even when the name is the same modulo a leading underscore.
The text was updated successfully, but these errors were encountered: