-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rename(refactor) support for record's named fields #53024
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'm not claiming that it was the correct decision, but the choice to not support refactoring for record fields was intentional. The rationale behind the decision is that, unlike classes, enums, and other nominal types, records are structurally typed. That means that the types of void f(({int first, int last}) a, ({int first, int last}) b) {} are the same type because of the shape of the record. There's actually nothing there, other than the shape to tell us that they're intended to be the same. In fact, if we change the name In other words, for a compiler that doesn't understand the semantics of the names, there's no reason to think that the two record types have any semantic relationship, or that both names should be changed if one of the names is selected. We could make an exception for an assignment and assume that the type on the left should always be associated with the type on the right, and that would likely always be true. But what we decided was that it would be confusing if 'rename' was sometimes available and sometimes not, so we decided it was better to never offer it. Interested to see what the community thinks. |
I think rename could be applied on locations where a shape is used. For example, let's take shape |
I think that's an interesting idea. I'd want to think through some concrete examples before committing to it in order to evaluate whether there are potentially confusing cases where using the shape would cause us to either rename too much or not rename enough, but I think it might be worth exploring. @scheglov Do we have information about which field names needed to be the same to resolve everything within a function or initializer expression? If not, is it information that we could collect? (Just trying to evaluate the feasibility of the proposed approach. |
A slightly related issue came up at Dart-Code/Dart-Code#5294, which is that LSP's Document Highlights also doesn't know how to relate these things together, so you don't get the same highlighting you do for class fields. I suspect if something was implemented to support renaming, it could also be used to improve that. |
I'd love for this to happen so record typedefs work the same as function typedefs. typedef MyFunc = void Function(int, {int value});
typedef MyRecord = (int, {int value}); The same rules applied to renaming the first should probably work to rename the second as well. |
I agree, feature parity would be good here. |
The text was updated successfully, but these errors were encountered: