[swift-evolution] Warning for vacuously complying to an all-optional protocol.
William Shipley
wjs at mac.com
Mon Apr 25 17:37:52 CDT 2016
The Swift 2.2 manual says:
NOTE
Strictly speaking, you can write a custom class that conforms to CounterDataSource without implementing either protocol requirement. They are both optional, after all. Although technically allowed, this wouldn’t make for a very good data source.
I think it’d be helpful to get a compiler warning when you declare that a class or struct complies to a protocol (that only has optional methods) but doesn’t actually implement any of the protocol.
E.G., this show show a warning:
import Cocoa
class kindaUseless: NSObject, NSTableViewDelegate {
}
While this behavior is mathematically consistent, it’s not rational and doesn’t really fit in with Swift.
Extraneous protocol conformance is messy and I can’t imagine a scenario in which it’s actually useful.
Thoughts?
-W
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160425/29d190c9/attachment.html>
More information about the swift-evolution
mailing list