The following code won't compile for reasons we're familiar with:
protocol Value {
associatedType ValueType
var value: ValueType { get set }
}
struct ValueHolder {
var value: Value // Protocol 'Value' can only be used as a generic
constraint because it has Self or associated type requirements
}
But then when I make that associated type concrete in a more sub-protocol,
the compiler still complains, even when it should no longer have associated
type requirements, because ValueType can only be Int.
protocol IntValue: Value {
associatedType ValueType = Int
var value: Int { get set }
}
struct ValueHolder {
var value: IntValue // Protocol 'IntValue' can only be used as a
generic constraint because it has Self or associated type requirements
}
or at least - that's what I'm trying to achieve with `associatedType
ValueType = Int`. Similarly I tried `typealias ValueType = Int`, with the
same result.
Would this be considered a compiler bug? Or is IntValue's ValueType
shadowing Value's ValueType, and they're both still independent? I don't
believe the latter case is correct because even when the original
declaration ValueType is concrete, the compiler still complains:
protocol IntValue {
associatedType ValueType = Int
var value: Int { get set }
}
struct ValueHolder {
var value: IntValue // Protocol 'IntValue' can only be used as a
generic constraint because it has Self or associated type requirements
}
Trying to figure out where this proposal would fall, or if it's been
discussed already - I wasn't able to find anything similar.
Cheers,
*Austin Feight *| Chief Shipping Officer
150 E. 52nd Street, 22nd Floor, New York, NY 10022
www.chexology.com <http://www.coatchex.com/> | www.austindfeight.com