You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Self" is shorthand for "Binding<Value>" in this case. Even without "Self", there's no way to do what you want here, which is to refer to the "Value" generic parameter from the outer scope. Once a generic parameter name has been shadowed, any reference to that name will always refer to the innermost definition.
Perhaps the best way is to rename the "Value" generic parameter of the subscript to something else?
_ Once a generic parameter name has been shadowed, any reference to that name will always refer to the innermost definition._
That doesn't seem correct to me, but I have to be missing something. Why has the following compiled fine over the past year, but not what I've posted above?
public extension Dictionary {
/// Group key-value pairs by their keys.
///
/// - Parameter pairs: Either `Swift.KeyValuePairs<Key, Self.Value.Element>`
/// or a `Sequence` with the same element type as that.
/// - Returns: `[KeyValuePairs.Key: [KeyValuePairs.Value]]`
init<Value, KeyValuePairs: Sequence>(grouping pairs: KeyValuePairs)
where
KeyValuePairs.Element == (key: Key, value: Value),
Self.Value == [Value]
{
self =
Dictionary<Key, [KeyValuePairs.Element]>(grouping: pairs, by: \.key)
.mapValues { $0.map(\.value) }
}
/// Group key-value pairs by their keys.
///
/// - Parameter pairs: Like `Swift.KeyValuePairs<Key, Self.Value.Element>`,
/// but with unlabeled elements.
/// - Returns: `[KeyValuePairs.Key: [KeyValuePairs.Value]]`
init<Value, KeyValuePairs: Sequence>(grouping pairs: KeyValuePairs)
where
KeyValuePairs.Element == (Key, Value),
Self.Value == [Value]
{
self.init( grouping: pairs.map { (key: $0, value: $1) } )
}
}
Environment
Xcode 12.3 beta
Additional Detail from JIRA
md5: 2783c3ac914f337886bcd7289fdefffa
Issue Description:
Example: this results in the error "`Value` is not a member of `Binding<Value>`".
It makes for ugly naming.
The text was updated successfully, but these errors were encountered: