[swift-evolution] Warning for vacuously complying to an all-optional protocol.

Douglas Gregor dgregor at apple.com
Mon Apr 25 22:11:31 CDT 2016


> On Apr 25, 2016, at 3:37 PM, William Shipley via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 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?


It should be a straightforward compiler warning to add. Want to file a bug at bugs.swift.org <http://bugs.swift.org/>? It would make a good starter bug.

	- Doug


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


More information about the swift-evolution mailing list