-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SE-0036: Requiring Leading Dot Prefixes for Enum Instance Member Implementations #2224
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
I also submitted a pull request to swift-package-manager to update its code for the changes: #260 |
0f2c3b1
to
2688e72
Compare
Interesting. I'm only realizing now that SE-0036 isn't precise enough: does it mean enums have to be accessed as static members (this patch), or that enum cases should never be found via unqualified lookup, even in static methods? Please add a test with a static method either way. |
Ah, I see that case is actually called out in the "Detail Design" section, and I see your test for it as well now. My bad. |
@@ -93,6 +93,9 @@ ERROR(could_not_use_type_member,none, | |||
ERROR(could_not_use_type_member_on_instance,none, | |||
"static member %1 cannot be used on instance of type %0", | |||
(Type, DeclName)) | |||
ERROR(could_not_use_enum_element_on_instance,none, | |||
"enum element %0 cannot be referenced as instance members", |
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.
Singular/plural mismatch here. How about "…as an instance member"?
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.
Sounds good, I’ll change it
I updated the error message and added a fix-it to suggest the full type name. This changed the code in CSDiag.cpp, the error message in DiagnosticsSema.def and of course the test cases in test/Parse/enum.swift. Can you have a look again? |
@jrose-apple can you take a look? |
llvm::raw_string_ostream typeNameStream(enumTypeName); | ||
typeNameStream << parentEnum->getNameStr(); | ||
if (auto genericParams = parentEnum->getGenericParams()) { | ||
genericParams->print(typeNameStream); |
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.
Won't this include constraints and things we don't want? (Please add that to your test either way.)
Actually, in 99% of cases the generic parameters will be assumed anyway, so maybe it'd be better to just leave them out.
Sorry for the delay! Aside from my low-level comments, I think always adding the fully-qualified name is the wrong way to go. If a fix-it isn't code that most users would actually accept, we shouldn't offer it. If there's not an easy way to detect whether the fully-qualified name is the right way to go, or whether the single dot would work, we should just leave it out for now. |
2e9b1f9
to
fd32b4b
Compare
That was my initial concern as well. I can’t think of a way to determine if a single dot suffices since it depends on the parent of the expression that caused the error and I can’t think of a way to determine it. I just though it would be helpful for the migration assistant to offload the migration work to the IDE instead of the developer. |
We can always improve the diagnostic later if we think of something. This is looking good! @swift-ci Please test |
Sorry, missed one declaration in the standard library when resolving merge conflicts. Don’t know why my local tests didn’t catch it. Should be resolved now. Testing locally but am pretty sure it was the only case. Could you try again? Update: Local test succeeded after change |
@swift-ci Please test |
Probably unrelated? @swift-ci Please test Linux platform |
@swift-ci Please test |
I didn’t know there were tests for the swift-pm that could fail because of this. I submitted a pull request for swift-pm to incorporate the changes: swiftlang/swift-package-manager#325 As to the failings on Linux, I’ve got no idea what caused them and don’t have a Linux machine to test it on, but it seems unrelated to my changes to me… |
@swift-ci test |
I'm going to ignore the LLDB failures. Thanks, Alex! |
The LLDB failures are breaking a number of the Jenkins bots. Is someone looking into fixing those? |
I’ve been getting CI failure emails that I think are meant for @ahoppen, coming from this PR. And I haven’t touched Swift in a while, so I’ve just been deleting them. That might be why nobody’s been looking into the failures. |
Todd Fiala just committed a fix for the LLDB failures. I'm following up on fixing the confusion between Alex Hoppen and Alex Chan. |
Ah, then I apologize for assuming they were unrelated! @tfiala, I'll be more careful in the future. |
No worries, @jrose-apple :-) |
I am going to need to revert this. What I have found from running this change on various code is that there is no migration help. We provide no fixits for missing dots, |
For example, for things like this: func staticReferencInInstanceMethod() {
let _ = A // expected-error {{enum element 'A' cannot be referenced as an instance member}}
let _ = SE0036.A
} We should have a Fix-it, not just an error. Also, for things like this: switch something {
case enumCase(let i): Right now we get "invalid pattern". We need a fixit and a better error to help users move forward. |
For reference, his was reverted in #2477. |
@ahoppen I really appreciate you working on this. I know this has taken some iteration, but this just needs some more refinement before it can land. This became apparent when I saw the fallout from landing this change. |
Hm. We had a fix-it earlier, and found that it usually didn't match what users would naturally use: it inserted the full name of the enum rather than just a dot. |
@@ -93,6 +93,9 @@ ERROR(could_not_use_type_member,none, | |||
ERROR(could_not_use_type_member_on_instance,none, | |||
"static member %1 cannot be used on instance of type %0", | |||
(Type, DeclName)) | |||
ERROR(could_not_use_enum_element_on_instance,none, | |||
"enum element %0 cannot be referenced as an instance member", |
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.
In fact I think it would be better if the diagnostic just said the leading dot is required
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 only works if in a contextual position where a leading dot will work.
First of all a big thanks to @tfiala for fixing the issues that I caused in LLDB and sorry for all the trouble caused. This weekend I will go and have a look whether I can come up with an idea on how the determine if a dot suffices in a fix-it that I didn’t think of before. I will report back then. |
I am going to work on improving exposure of build-related failures during an LLDB test run (I.e. when an LLDB test fails to compile a test subject, like a .swift, .cpp or .c program that will be used during testing). The intent will be to make this show up neatly in the Swift CI test output. That’ll go a long way to making it more obvious when a Swift change requires modifying some LLDB test subject .swift/.c/.cpp files.
|
I created an updated pull request with fix its: #2634 |
What's in this pull request?
Implemented SE-0036: Requiring Leading Dot Prefixes for Enum Instance Member Implementations
Resolved bug number: SR-1236
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
Validation Testing
Note: Only members of the Apple organization can trigger swift-ci.