-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Refactoring] SR-6051 Expansion of switch
statement missing cases
#12281
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
Conversation
lib/IDE/Refactoring.cpp
Outdated
SubjectED = SubjectTy->getAnyNominal()->getAsEnumOrEnumExtensionContext(); | ||
} | ||
if (!SubjectED) { | ||
DiagEngine.diagnose(ExpandedStmtLoc, diag::no_subject_enum); |
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.
This... isn’t correct. For one you can switch over arbitrary expressions. For two, tuple patterns exist. So isApplicable
should probably be updated to take into account what expressions this action can handle.
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.
It's actually how Expand Default is implemented right now, before this PR is introduced. I've just moved the code and generalized it to add handling when switch
is selected. You're right — I will fix isApplicable
in both Expand Default
and Expand Switch Cases
. Thanks!
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.
Oh, sorry that wasn't your bug. Syntactic expansion here is a very nuanced topic for me 😄
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.
It's great that you've spotted this. There are couple other places like that in Expand Default
performChange
— where we could move the checking to isApplicable
. It's a perfect moment to... refactor it :)
@nkcsgexi @CodaFi Currently in
What's the reason to do this? Should we move it also to the |
@Kacper20 I think moving it to |
Yep, thanks for the answer! So let's wait with the review — I will update it tomorrow with the changes :) |
5cd3ac5
to
3e8885a
Compare
bdbcf6f
to
5a6ce45
Compare
@CodaFi I think it's ready to review — I've moved the checking to |
switch
statement missing casesswitch
statement missing cases
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.
Just one change request. Everything else looks much improved. Thanks!
lib/IDE/Refactoring.cpp
Outdated
@@ -633,6 +633,15 @@ class TokenBasedRefactoringAction : public RefactoringAction { | |||
} | |||
}; | |||
|
|||
struct ApplicabilityContext { |
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.
All of this is just to get the SourceFile
plumbed into that helper function, right? But every refactoring action has access to TheFile
anyway. You can probably revert this (and add a non-public accessor if you need it).
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.
Yeah, that's the reason. The problem is that action has static isApplicable()
method and isApplicable
which is not static calls static one and is not overridable. It'll now have access to the file through ResolvedRangeInfo
, as discussed in: #12268
Thanks!
…hen cursor is placed on `switch` keyword
…user at the moment refactoring is invoked
…next to each other
7d922b3
to
5425dc1
Compare
@CodaFi Thanks! Fixed now. |
@CodaFi could you run the tests? |
@swift-ci please smoke test |
Refactor is available when the cursor is placed on
switch
keyword.There are still a few more tests to be written so it's WIP.
Addresses SR-6051.
cc @nkcsgexi