[swift-evolution] two protocols with the same method name
Howard Lovatt
howard.lovatt at gmail.com
Fri Jan 8 20:19:12 CST 2016
I donβt really get what you are driving at. If I rework your example so that it runs:
//π
protocol A {
var ring: String { get }
}
//π
protocol B {
var ring: String { get set }
}
class X: A, B {
var _ring = "π"
var ring: String {
get {
return _ring
}
set {
self._ring = newValue
}
}
}
let x = X()
(x as A).ring // π
(x as B).ring // π
x.ring // π
x.ring = "π"
x.ring // π
// (x as A).ring = "π" Error, A doesn't have set
Then the behaviour is exactly what I would expect.
> On 7 Jan 2016, at 9:18 PM, 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160109/573d2b71/attachment.html>
More information about the swift-evolution
mailing list