Thanks, what I still don't understand though, is the following behavior, ie how to answer questions [1] and [2] in this program:
protocol P {
associatedtype A = Bool
}
extension P where Self: BinaryFloatingPoint {
typealias A = Float
}
func foo<T: P>(_: T.Type) {
print(T.A.self)
}
extension Double: P {}
extension String: P {}
foo(Double.self) // Prints Float
foo(String.self) // Prints Float … [1]: Why/how?
print(Double.A.self) // Prints Float
//print(String.A.self) // Doesn't compile … [2]: Why not? (Error msg makes no sense to me.)
I just can't understand the current behavior, I would expect this program to compile and print:
Float
Bool
Float
Bool
You've already addressed this upthread and said the current behavior is wrong:
But I think this program exemplifies what most would perceive as basic/normal usage of Swift generics, ie this does not look very complicated:
protocol P {
associatedtype A = Bool
}
extension P where Self: BinaryFloatingPoint {
typealias A = Float
}
and I think most people would agree on what they think it means. So the current behavior / bug(s) seem kind of serious IMHO.
Does your "until there's an actual design" mean that there is no intended behavior for this example program?
I created this thread in case there isn't, to see if people have the same expectations or not.