[SR-511][Parse] Add 'associatedtype' keyword and fixit#964
[SR-511][Parse] Add 'associatedtype' keyword and fixit#964DougGregor merged 1 commit intoswiftlang:masterfrom
Conversation
There was a problem hiding this comment.
Can we tighten this wording up a bit, and quote the keywords? Perhaps:
"use of 'typealias' to declare associated types is deprecated; use 'associatedtype' instead"
?
|
I think that a specific diagnostic for the case of writing 'associatedtype' in a non-protocol would be useful. Something like associated types can only be defined in a protocol; define a type or introduce a 'typealias' to satisfy an associated type requirement |
|
Otherwise, this looks great! |
|
@DougGregor Thanks for the better language on the diagnoses! Committed those fixes. |
|
Can you squash these and then I'll merge? |
Adds an associatedtype keyword to the parser tokens, and accepts either typealias or associatedtype to create an AssociatedTypeDecl, warning that the former is deprecated. The ASTPrinter now emits associatedtype for AssociatedTypeDecls. Separated AssociatedType from TypeAlias as two different kinds of CodeCompletionDeclKinds. This part probably doesn’t turn out to be absolutely necessary currently, but it is nice cleanup from formerly specifically glomming the two together. And then many, many changes to tests. The actual new tests for the fixits is at the end of Generics/associated_types.swift.
|
@dabrahams No, the typealias isn't required at all, but it does appear to be a fairly common pattern to write something like it - @DougGregor 's suggested diagnosis text is great for telling people it isn't needed. Also: squashed! |
[SR-511][Parse] Add 'associatedtype' keyword and fixit
Adds an associatedtype keyword to the parser tokens, and accepts either
typealias or associatedtype to create an AssociatedTypeDecl, warning
that the former is deprecated. The ASTPrinter now emits associatedtype
for AssociatedTypeDecls.
Separated AssociatedType from TypeAlias as two different kinds of
CodeCompletionDeclKinds. This part probably doesn’t turn out to be
absolutely necessary currently, but it is nice cleanup from formerly
specifically glomming the two together.
And then many, many changes to tests. The actual new test for the fixit
is at the end of Generics/associated_types.swift.
There is one open question at the moment, which is what should happen
with using associatedtype in a non-Protocol context:
Currently the code still expects typealias in the struct, and it is a
typealias as far as the compiler is concerned. But I can certainly
imagine users mistakenly thinking that they are ‘assigning’ a specific type to an
associatedtype instead. With this current commit, using the
associatedtype keyword there will assert an unexpected token. It should
either accept it or have a nice error, and I’m not sure which.