Skip to content

Commit fedfc58

Browse files
committed
(SE-0011) change proposed keyword to associatedtype
1 parent 264600f commit fedfc58

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

proposals/0011-replace-typealias-associated.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Replace `typealias` keyword with `associated` for associated type declarations
1+
# Replace `typealias` keyword with `associatedtype` for associated type declarations
22

33
* Proposal: [SE-0011](https://github.com/apple/swift-evolution/blob/master/proposals/0011-replace-typealias-associated.md)
44
* Author(s): [Loïc Lecrenier](https://github.com/loiclec)
@@ -16,7 +16,7 @@ These two kinds of declarations are different and should use distinct keywords.
1616
This would emphasize the difference between them and reduce some of the
1717
confusion surrounding the use of associated types.
1818

19-
The proposed new keyword is `associated`.
19+
The proposed new keyword is `associatedtype`.
2020

2121
## Motivation
2222

@@ -26,7 +26,7 @@ Re-using `typealias` for associated type declarations is confusing in many ways.
2626
other places.
2727
2. It hides the existence of associated types to beginners, which allows them
2828
to write code they misunderstand.
29-
3. It hides the absence of concrete type aliases inside protocols.
29+
3. It is not clear that concrete type aliases are forbidden inside protocols.
3030

3131
In particular, **2 + 3** leads to programmers writing
3232

@@ -59,7 +59,7 @@ understand.
5959

6060
## Proposed solution
6161

62-
For declaring associated types, replace the `typealias` keyword with `associated`.
62+
For declaring associated types, replace the `typealias` keyword with `associatedtype`.
6363

6464
This solves the issues mentioned above:
6565

@@ -72,30 +72,30 @@ This eliminates the confusion showed in the previous code snippets.
7272

7373
```swift
7474
protocol Prot {
75-
associated Container : SequenceType
75+
associatedtype Container : SequenceType
7676
typealias Element = Container.Generator.Element // error: cannot declare type alias inside protocol, use protocol extension instead
7777
}
7878
```
7979

8080
```swift
8181
protocol Prot {
82-
associated Container : SequenceType
82+
associatedtype Container : SequenceType
8383
}
8484
extension Prot {
8585
typealias Element = Container.Generator.Element
8686
}
8787
```
8888

89-
Alternative keywords considered: `withtype`, `associatedtype`, `typeassociation`, `type`
89+
Alternative keywords considered: `type`, `associated`, `requiredtype`, `placeholdertype`, …
9090

9191
## Proposed Approach
9292

93-
For declaring associated types, I suggest adding `associated` and deprecating
93+
For declaring associated types, I suggest adding `associatedtype` and deprecating
9494
`typealias` in Swift 2.2, and removing `typealias` entirely in Swift 3.
9595

9696
## Impact on existing code
9797

98-
As it simply replaces one keyword for another, the transition to `associated`
98+
As it simply replaces one keyword for another, the transition to `associatedtype`
9999
could be easily automated without any risk of breaking existing code.
100100

101101
## Mailing List

0 commit comments

Comments
 (0)