Skip to content

[CSDiagnostics] Offer protocol conformance fix-it in ContextualFailure #27026

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 5 commits into from
Sep 5, 2019
Merged

[CSDiagnostics] Offer protocol conformance fix-it in ContextualFailure #27026

merged 5 commits into from
Sep 5, 2019

Conversation

theblixguy
Copy link
Collaborator

@theblixguy theblixguy commented Sep 4, 2019

If we're assigning a value of concrete type to a protocol type but the type does not conform to the protocol and it's the same as the decl context's type, then offer a fix-it to add the conformance.

For example:

protocol Foo {}

class Bar1 {
  var prop: Foo?
}

class Bar2 {
  let bar1 = Bar1()
  
  func method() {
    bar1.prop = self // offer fix-it to conform 'Bar2' to 'Foo'
  }
}

Resolves SR-11412.

@theblixguy theblixguy requested a review from xedin September 4, 2019 20:23
@theblixguy
Copy link
Collaborator Author

theblixguy commented Sep 4, 2019

This is my initial implementation, but let me know your thoughts :)

Copy link
Contributor

@owenv owenv left a comment

Choose a reason for hiding this comment

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

It's nice to see this get picked up so quickly!

This isn't a full review, just had a couple of comments.

Also, what do you think about offering to add requirement stubs when in editor mode? As is, applying this fix-it will usually result in the 'missing requirements' error and the fix-it to add stubs.

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

I think this is a great idea!

@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test

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.

3 participants