[swift-evolution] Keyword for protocol conformance

Sean Heber sean at fifthace.com
Tue Aug 23 09:32:43 CDT 2016


Just want to add my voice to the chorus of “this has happened to me too.”

l8r
Sean


> On Aug 23, 2016, at 2:13 AM, Charles Srstka via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> 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
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list