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

Grzegorz Leszek grzesiek.leszek at gmail.com
Thu Jan 7 04:18:37 CST 2016


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!


More information about the swift-evolution mailing list