Skip to content
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

Provide a custom diagnostic for conformance to NSObjectProtocol #28591

Merged
merged 2 commits into from Dec 5, 2019

Conversation

DougGregor
Copy link
Member

Swift classes cannot meaningfully conform to NSObjectProtocol.
Inheriting from NSObject is the appropriate fix, so suggest that.
Fixes rdar://problem/32543753.

The diagnostic now looks like this:

proto.swift:3:7: error: cannot declare conformance to 'NSObjectProtocol' in Swift; 'Foo' should inherit 'NSObject' instead
class Foo: NSObjectProtocol { }
      ^    ~~~~~~~~~~~~~~~~
           NSObject

Swift classes cannot meaningfully conform to NSObjectProtocol.
Inheriting from NSObject is the appropriate fix, so suggest that.
Fixes rdar://problem/32543753.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test and merge

Copy link
Contributor

@beccadax beccadax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing you might tweak, but otherwise looks alright!

// One cannot meaningfully declare conformance to the NSObject protocol
// in Swift. Suggest inheritance from NSObject instead.
if (isNSObjectProtocol(Proto)) {
if (T->getClassOrBoundGenericClass()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the surrounding code—does this call return the same class you dyn_cast<ClassDecl>() to get later?

@swift-ci swift-ci merged commit b7d0264 into apple:master Dec 5, 2019
@DougGregor DougGregor deleted the nsobject-protocol-conformance branch December 5, 2019 21:25
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.

None yet

5 participants