[swift-evolution] two protocols with the same method name

Jordan Rose jordan_rose at apple.com
Thu Jan 7 19:40:31 CST 2016


Mm. There are two cases here:

- Two protocols use the same method name for completely unrelated things.
- Two protocols use the same method name for similar things.

In the latter case, having one method satisfy both requirements is probably fine. In the former, there would definitely be a problemโ€ฆbut I have a hard time thinking of a type that should actually conform to two protocols that do completely different things and yet manage to use the same name for something. Do you have a real-life example where this has been a problem? Everything I can find online looks contrived.

Jordan


> On Jan 7, 2016, at 2:18, Grzegorz Leszek via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I suggest compile warning if one classes/structs/enums implements
> protocols with the same name.
> It could lead to confusions, when methods of those protocols will mean
> different things.
> It will force to implement parent protocol with shared methods or
> change method in one of the protocols.
> Below is an example.
> Regards,
> Greg
> 
> //๐Ÿ’
> protocol A {
>  var ring: String { get }
> }
> 
> //๐Ÿ””
> protocol B {
>  var ring: String { get set }
> }
> 
> class X: A, B {
>  var ring: String {
>    get {
>      return "๐Ÿ’"
>    }
>    set {
>      self.ring = newValue
>    }
>  }
> }
> let x = X()
> let somewhereInTheProject = "\(x.ring) the bell"
> x.ring = "๐Ÿ””" // ERROR!
> _______________________________________________
> 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