DeskA
1
extension Array {
struct Results {
var count: Int = 1
}
}
struct SomeStruct<T> {
var items = [Int: [T].Results]() // ERROR: Generic struct 'Dictionary' requires that 'Int.Type' conform to 'Hashable'
}
Is there a reason this isn't allowed? Using the full Array<T> notation does work fine:
extension Array {
struct Results {
var count: Int = 1
}
}
struct SomeStruct<T> {
var items = [Int: Array<T>.Results]() // compiles
}
1 Like
jrose
(Jordan Rose)
2
It looks like the compiler is interpreting this as [Int.self: [T].Results.self], i.e. a dictionary literal with one entry, probably because it doesn't know that you can access type members after using the sugared syntax for arrays and dictionaries. Can you file a bug at https://bugs.swift.org?
3 Likes
Yeah, it looks like a bug. On master compiler, I get:
/Users/spare/Desktop/test.swift:8:14: error: cannot call value of non-function type '[Int.Type : Array<T>.Results.Type]'
var items = [Int: [T].Results]()
^ ~~
/Users/spare/Desktop/test.swift:8:14: error: type 'Int.Type' cannot conform to 'Hashable'; only concrete types such as structs, enums and classes can conform to protocols
var items = [Int: [T].Results]()
^
/Users/spare/Desktop/test.swift:8:14: note: required by generic struct 'Dictionary' where 'Key' = 'Int.Type'
var items = [Int: [T].Results]()
^
DeskA
4
1 Like