Allow access of nested types through syntactic sugar

Hi,
I'm trying to declare a type alias in Dictionary

I declared a struct

struct FullDictionary<Key, Value> where Key : Hashable & CaseIterable

and I'd like to access it from Dictionary
so I did the following

extension Dictionary where Key : CaseIterable {
  typealias Full = FullDictionary<Key, Value>
}

struct Test {
  var x: Dictionary<MyEnum, String>.Full
  var y: [MyEnum: String].Full
}

x compiles but y doesn't
After some investigations, I found out that it's a limitation of Swift Grammar

We have the following rules:

type → dictionary-type

type → type-identifier

The second rule allows usage of nested types, while the first allows syntactic sugar for dictionaries

Would it be possible to add more rules to allow the behavior above?
I'm thinking something like

type → dictionary-type.type-identifier

such a rule could be added for arrays/dictionaries/optionals
what do you think?

Yes I agree, I’ve always found this limitation weird. Same thing with Array.

Made extra counter-intuitive by the fact that we have a linting community (SwiftLint) enforcing use if sugar syntax [Element] instead of Array<Element>.

Hi Sajjon,
I'm new to this forum so I don't know what I should do now
Is there some kind of process I need to go through to submit this to Swift Evolution?

if you add this, you would probably also want to add

type := <array-type> . <type-identifier>
type := <optional-type> . <type-identifier>

for completeness. the optional-type one might look suspiciously like an optional chaining expression though.

This is a bug tracked by SR-5108, though Optional types aren't included there. That one might need more discussion.

Yes, it seems to be known with multiple duplicates. However, all of them seem "stuck", is there a mechanism to "upvote" certain bugs? What can I do to help get it fixed?

Terms of Service

Privacy Policy

Cookie Policy