When I inherit a protocol adding mutating keyword to the property with the same name from the parent protocol, I can't create a concrete type even there's no compile error for the protocols.
Check out this code:
protocol FooProtocol {
var value: Int { get }
}
protocol MutatingFooProtocol: FooProtocol {
var value: Int { mutating get }
}
// no compile error so far.
struct Bar: MutatingFooProtocol {
private var storage: Int
var value: Int {
mutating get {
self.storage += 1
return self.storage
}
}
}
This produces compile error that Bar
is not conforming to protocol FooProtocol
. but adding non mutating var value: Int
does not solve the problem. It creates another compile error Invalid redeclaration of 'value'
.