"does not conform to protocol" --> Tell me what to add

I've noticed in Xcode there are a lot of fixits that tell you exactly what
to do to "fix it", and it will do it for you. However, this does not apply
to "does not conform to protocol" errors; I'm wondering if it is possible
for the fixit engine to add methods/properties such that, at a minimum, a
user knows what to actually add/implement to get protocol conformance.

···

--
Joseph Bell

@iachievedit

Xcode does tell you which members are not present; they're in the notes for the "does not conform" message, which you can see in the Issue Navigator or Log Navigator. I'm pretty sure we have an outstanding Radar about making fix-its for these too, but it's hard to know where in your type or extension you'd want the extra members to appear. Still, I suppose you could move them.

It's probably best to file this as an Improvement request at bugs.swift.org.

Jordan

···

On Apr 20, 2016, at 16:37, Joseph Bell via swift-dev <swift-dev@swift.org> wrote:

I've noticed in Xcode there are a lot of fixits that tell you exactly what to do to "fix it", and it will do it for you. However, this does not apply to "does not conform to protocol" errors; I'm wondering if it is possible for the fixit engine to add methods/properties such that, at a minimum, a user knows what to actually add/implement to get protocol conformance.

--
Joseph Bell
iAchieved.it – Thoughts from a Technology Leader
@iachievedit
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

It is absolutely possible and would be a wonderful improvement. The trickiest part comes down to synthesizing the right declaration (basically, creating what the user should have written) so it can be presented to the user in the Fix-It text. We actually have some code that does something similar. Try this in Xcode:

class A {
  required init(x: Int, y: String) { }
}

class B : A {
  init() {
    super.init(x: 5, y: "hello")
  }
}

and you get a Fix-It that adds the missing required initializer:

  required init(x: Int, y: String) {
    fatalError("init(x:y:) has not been implemented")
  }

(That’s lib/Sema/TypeCheckDecl.cpp’s diagnoseMissingRequiredInitializer(), FWIW).

  - Doug

···

On Apr 20, 2016, at 4:37 PM, Joseph Bell via swift-dev <swift-dev@swift.org> wrote:

I've noticed in Xcode there are a lot of fixits that tell you exactly what to do to "fix it", and it will do it for you. However, this does not apply to "does not conform to protocol" errors; I'm wondering if it is possible for the fixit engine to add methods/properties such that, at a minimum, a user knows what to actually add/implement to get protocol conformance.