Primary associated types have made it so that I hardly need this anymore , but it's not always possible to use them.
enum E<T> {
typealias π«1 = T // compiles
typealias π«2 = Self.T // 'T' is not a member type of generic enum 'E<T>'
typealias π«3 = E.T // same
typealias π«4 = E<T>.T // same
}
Is the bug just with the bad error message, or should no error be generated?
Protocols don't exhibit the restriction.
protocol P<T> {
associatedtype T
typealias π«1 = T // compiles
typealias π«2 = Self.T // compiles
typealias π«3 = P.T // Cannot access associated type 'T' from 'P'; use a concrete type or generic parameter base instead
typealias π«4 = P<T>.T // same
}
And why does it sometimes work? E.g. this compiles:
public extension Dictionary {
/// Group key-value pairs by their keys.
///
/// - Parameter pairs: Either `KeyValuePairs<Key, Self.Value.Element>`
/// or a `Sequence` with the same element type as that.
/// - Returns: `[Key: [Value]]`
init<Value>(grouping pairs: some Sequence<(key: Key, value: Value)>)
where Self.Value == [Value] {
self = [_: _](grouping: pairs, by: \.key).mapValues { $0.map(\.value) }
}
β¦but
extension E {
// 'T' is not a member type of generic struct 'E<T>'
func Ζ<T>(_: some Sequence<T>) where Self.T == [T] { }
}