[swift-evolution] Keyword for protocol conformance

Charles Srstka cocoadev at charlessoft.com
Tue Aug 23 02:13:21 CDT 2016


> On Aug 23, 2016, at 12:11 AM, Charlie Monroe <charlie at charliemonroe.net> wrote:
> 
> I don't see it as sub-par in this example (this actually happened to me):
> 
> @objc protocol Foo {
> 	optional func bar()
> }
> 
> class FooImpl: Foo {
> 	func bar() { ... }
> }
> 
> Now imagine that bar() gets renamed in the protocol to baz(). You get no warnings, nothing - since the bar() was optional (or can have default implementation as Chalers mentioned). FooImpl still conforms to Foo and bar() can live on there happily.

Had that happen to me a bunch of times, especially when I realize that the method needs to have one more argument and then forget to add it everywhere (which is harder to use search-and-replace for, as well).

Here’s another case where this can bite you:

In file P.swift:

protocol P {
	func foo()
}

extension P {
	func foo()
}

In another file, S.swift:

struct S: P {}

Imagine I rename foo in the protocol, but forget to rename it in the extension. The method no longer has a default implementation, and we do indeed get an error, but the error’s in S.swift, in the wrong place. S complains that it doesn’t conform to the protocol. If there were a keyword on foo() in the extension, the compiler warning would be right where the problem is as soon as I renamed the method in the protocol, and it’d be a 2-second fix.

Charles

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160823/a824896b/attachment.html>


More information about the swift-evolution mailing list