Skip to content

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

Merged
merged 3 commits into from
May 11, 2016

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Apr 17, 2016

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:

  • Test pull request on Swift continuous integration.

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

Platform Comment
All supported platforms @swift-ci Please smoke test
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
OS X platform @swift-ci Please test OS X platform
Linux platform @swift-ci Please test Linux platform

Note: Only members of the Apple organization can trigger swift-ci.

@ahoppen
Copy link
Member Author

ahoppen commented Apr 17, 2016

I also submitted a pull request to swift-package-manager to update its code for the changes: #260

@ahoppen ahoppen force-pushed the SR-1236 branch 2 times, most recently from 0f2c3b1 to 2688e72 Compare April 17, 2016 15:10
@jrose-apple
Copy link
Contributor

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.

@jrose-apple
Copy link
Contributor

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",
Copy link
Contributor

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"?

Copy link
Member Author

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

@ahoppen
Copy link
Member Author

ahoppen commented Apr 20, 2016

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?

@tkremenek
Copy link
Member

@jrose-apple can you take a look?

llvm::raw_string_ostream typeNameStream(enumTypeName);
typeNameStream << parentEnum->getNameStr();
if (auto genericParams = parentEnum->getGenericParams()) {
genericParams->print(typeNameStream);
Copy link
Contributor

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.

@jrose-apple
Copy link
Contributor

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.

@ahoppen ahoppen force-pushed the SR-1236 branch 6 times, most recently from 2e9b1f9 to fd32b4b Compare May 5, 2016 15:31
@ahoppen
Copy link
Member Author

ahoppen commented May 5, 2016

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.
But since you think otherwise, I removed the fix-it again.

@jrose-apple
Copy link
Contributor

We can always improve the diagnostic later if we think of something. This is looking good!

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented May 5, 2016

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

@jrose-apple
Copy link
Contributor

@swift-ci Please test

@jrose-apple
Copy link
Contributor

Probably unrelated?

@swift-ci Please test Linux platform

@DougGregor
Copy link
Member

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented May 7, 2016

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…

@tkremenek
Copy link
Member

@swift-ci test

@jrose-apple
Copy link
Contributor

I'm going to ignore the LLDB failures. Thanks, Alex!

@jrose-apple jrose-apple merged commit 14a7334 into swiftlang:master May 11, 2016
@bob-wilson
Copy link
Contributor

The LLDB failures are breaking a number of the Jenkins bots. Is someone looking into fixing those?

@alexwlchan
Copy link
Contributor

alexwlchan commented May 11, 2016

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.

@bob-wilson
Copy link
Contributor

Todd Fiala just committed a fix for the LLDB failures. I'm following up on fixing the confusion between Alex Hoppen and Alex Chan.

@jrose-apple
Copy link
Contributor

Ah, then I apologize for assuming they were unrelated! @tfiala, I'll be more careful in the future.

@tfiala
Copy link
Contributor

tfiala commented May 11, 2016

No worries, @jrose-apple :-)

@tkremenek
Copy link
Member

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, case statements simply say "invalid pattern" instead of suggesting a dot, etc. With this kind of breaking change we need better migration support.

@tkremenek
Copy link
Member

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.

@tkremenek
Copy link
Member

For reference, his was reverted in #2477.

@tkremenek
Copy link
Member

@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.

@jrose-apple
Copy link
Contributor

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",
Copy link
Contributor

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

Copy link
Contributor

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.

@ahoppen
Copy link
Member Author

ahoppen commented May 12, 2016

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.

@tfiala
Copy link
Contributor

tfiala commented May 12, 2016

On May 12, 2016, at 2:27 PM, Alex Hoppen [email protected] wrote:

First of all a big thanks to @tfiala https://github.com/tfiala for fixing the issues that I caused in LLDB and sorry for all the trouble caused.

No worries, Alex! It was fine.

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.

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.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub #2224 (comment)

@ahoppen
Copy link
Member Author

ahoppen commented May 21, 2016

I created an updated pull request with fix its: #2634

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants