-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Refactoring] Several improvements to memberwise initializer generation #58718
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
[Refactoring] Several improvements to memberwise initializer generation #58718
Conversation
@swift-ci Please smoke test |
…ise init Generating a memberwise init would skip over properties with property wrappers. Switch the implementation of memberwise init generation closer to the one that generates the implicit memberwise init by also using `getMembers()` instead of `getStoredProperties()`. rdar://89057767
…te an empty initializer instead of failing
4ad16cd
to
8862e01
Compare
@swift-ci Please smoke test |
…mberwise initializer Previously, we were dropping backticks, which might lead to invalid code if the type member was a keyword. rdar://81888671
@@ -3147,26 +3147,24 @@ bool RefactoringActionLocalizeString::performChange() { | |||
} | |||
|
|||
struct MemberwiseParameter { | |||
Identifier Name; | |||
CharSourceRange NameRange; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if Identifier
should have a bit for whether it needs backticks or not. I think there's a bunch of bugs involving not adding backticks and it'd be nice if we instead had a method in Identifier
that would get the actual text for the name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think it should because we use pointer equality to compare Identifier
s and we want to consider two identifiers identical even if one has backticks and the other doesn’t. In general, I think the usual compilation doesn’t care about backticks, it’s only us who care.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true. Just seems so wrong that we have to extract text here.
LGTM. I find it weird that we provide defaults for |
Oh - one more test you could add is for a member with get/set. |
…operties with getter and setter
@swift-ci Please smoke test |
Generating a memberwise init would skip over properties with property wrappers. Switch the implementation of memberwise init generation closer to the one that generates the implicit memberwise init by also using
getMembers()
instead ofgetStoredProperties()
.If type has no memberwise initializable members, generate an empty initializer instead of failing.
Previously, we were dropping backticks, which might lead to invalid code if the type member was a keyword. Maintain any backticks from type members in the generated memberwise initializer.
rdar://89057767
rdar://81888671