@@ -6,6 +6,7 @@ CHANGELOG
6
6
7
7
| Contents |
8
8
| :--------------------- |
9
+ | [ Swift Next] ( #swift-next ) |
9
10
| [ Swift 5.1] ( #swift-51 ) |
10
11
| [ Swift 5.0] ( #swift-50 ) |
11
12
| [ Swift 4.2] ( #swift-42 ) |
@@ -22,9 +23,112 @@ CHANGELOG
22
23
23
24
</details >
24
25
26
+ Swift Next
27
+ ----------
28
+
29
+ * [ SR-6118] [ ] :
30
+
31
+ Subscripts can now declare default arguments:
32
+
33
+ ``` swift
34
+ struct Subscriptable {
35
+ subscript (x : Int , y : Int = 0 ) {
36
+ ...
37
+ }
38
+ }
39
+
40
+ let s = Subscriptable ()
41
+ print (s[0 ])
42
+ ```
43
+
25
44
Swift 5.1
26
45
---------
27
46
47
+ * [ SE-0256] [ ] :
48
+
49
+ Subscripts can now be declared ` static ` or (inside classes) ` class ` .
50
+
51
+ * [ SE-0252] [ ] :
52
+
53
+ The existing ` @dynamicMemberLookup ` attribute has been extended with a
54
+ support for strongly-typed keypath implementations:
55
+
56
+ ``` swift
57
+ @dynamicMemberLookup
58
+ struct Lens <T > {
59
+ let getter: () -> T
60
+ let setter: (T) -> Void
61
+
62
+ var value: T {
63
+ get {
64
+ return getter ()
65
+ }
66
+ set {
67
+ setter (newValue)
68
+ }
69
+ }
70
+
71
+ subscript <U >(dynamicMember keyPath : WritableKeyPath<T, U>) -> Lens<U> {
72
+ return Lens< U> (
73
+ getter : { self .value [keyPath : keyPath] },
74
+ setter : { self .value [keyPath : keyPath] = $0 })
75
+ }
76
+ }
77
+ ```
78
+
79
+ * [ SR-8546] [ ] , [ SR-9043] [ ] :
80
+
81
+ More thorough checking has been implemented for restrictions around
82
+ escaping closures capturing ` inout ` parameters or values of noescape type.
83
+ While most code should not be affected, there are edge cases where
84
+ the Swift 5.0 compiler would accept code violating these restrictions.
85
+ This could result in runtime crashes or silent data corruption.
86
+
87
+ An example of invalid code which was incorrectly accepted by the Swift 5.0
88
+ compiler is an ` @escaping ` closure calling a local function which
89
+ references an ` inout ` parameter from an outer scope:
90
+
91
+ ``` swift
92
+ struct BadCaptureExample {
93
+ var escapingClosure: () -> ()
94
+
95
+ mutating func takesInOut (_ x : inout Int ) {
96
+ func localFunction () {
97
+ x += 1
98
+ }
99
+
100
+ escapingClosure = { localFunction () }
101
+ }
102
+ }
103
+ ```
104
+
105
+ The compiler now correctly diagnoses the above code by pointing out that
106
+ the capture of ` x ` by ` localFunction() ` is invalid, since ` localFunction() `
107
+ is referenced from an ` @escaping ` closure.
108
+
109
+ This also addresses certain cases where the compiler incorrectly diagnosed
110
+ certain code as invalid, when in fact no violation of restrictions had
111
+ taken place. For example,
112
+
113
+ ``` swift
114
+ func takesNoEscape (_ fn : () -> ()) {
115
+ func localFunction () {
116
+ fn ()
117
+ }
118
+
119
+ { localFunction () }()
120
+ }
121
+ ```
122
+
123
+ * [ SR-2672] [ ] :
124
+
125
+ Conversions between tuple types are now fully implemented.
126
+ Previously, the following would diagnose an error:
127
+
128
+ ``` swift
129
+ let values: (Int , Int ) = (10 , 15 )
130
+ let converted: (Int ? , Any ) = values
131
+
28
132
* [SE- 0242 ][]:
29
133
30
134
The memberwise initializer for structures now provide default values for variables that hold default expressions.
@@ -43,7 +147,22 @@ Swift 5.1
43
147
44
148
* [ SE-0068] [ ] :
45
149
46
- ` Self ` can now be used inside member functions and for function arguments of structs and enums to refer to the containing type.
150
+ It is now possible to use ` Self ` to refer to the innermost nominal
151
+ type inside struct, enum and class declarations. For example, the
152
+ two method declarations inside this struct are equivalent:
153
+
154
+ ``` swift
155
+ struct Box <Value > {
156
+ func transform1 () -> Self { return self }
157
+ func transform2 () -> Box<Value > { return self }
158
+ }
159
+ ```
160
+
161
+ In classes, ` Self ` is the dynamic type of the ` self ` value, as before.
162
+ Existing restrictions on ` Self ` in declaration types still apply;
163
+ that is, ` Self ` can only appear as the return type of a method.
164
+ However, ` Self ` can now be used inside the body of a method
165
+ without limitation.
47
166
48
167
* [ SR-7799] [ ] :
49
168
@@ -62,12 +181,12 @@ Swift 5.1
62
181
}
63
182
```
64
183
65
- * ` weak ` and ` unowned ` variables can now be used inside types that
66
- declare ` Equatable ` or ` Hashable ` conformance.
184
+ * ` weak ` and ` unowned ` stored properties no longer inhibit the
185
+ automatic synthesis of ` Equatable ` or ` Hashable ` conformance.
67
186
68
187
* [ SR-2688] [ ] :
69
188
70
- An ` @autoclosure ` closure can now be a typealias.
189
+ An ` @autoclosure ` parameter can now be declared with a typealias type .
71
190
72
191
``` swift
73
192
class Foo {
@@ -78,10 +197,12 @@ Swift 5.1
78
197
79
198
* [ SR-7601] [ ] :
80
199
81
- Functions marked with ` @objc ` can now return ` Self `
200
+ Methods declared ` @objc ` inside a class can now return ` Self ` :
82
201
83
202
``` swift
84
- @objc func returnDynamicSelf () -> Self { return self }
203
+ class MyClass : NSObject {
204
+ @objc func clone () -> Self { return self }
205
+ }
85
206
```
86
207
87
208
* [ SR-2176] [ ] :
@@ -7542,6 +7663,7 @@ Swift 1.0
7542
7663
[SR- 2388 ]: < https: // bugs.swift.org/browse/SR-2388>
7543
7664
[SR- 2394 ]: < https: // bugs.swift.org/browse/SR-2394>
7544
7665
[SR- 2608 ]: < https: // bugs.swift.org/browse/SR-2608>
7666
+ [SR- 2672 ]: < https: // bugs.swift.org/browse/SR-2672>
7545
7667
[SR- 2688 ]: < https: // bugs.swift.org/browse/SR-2688>
7546
7668
[SR- 4248 ]: < https: // bugs.swift.org/browse/SR-4248>
7547
7669
[SR- 5581 ]: < https: // bugs.swift.org/browse/SR-5581>
@@ -7551,3 +7673,5 @@ Swift 1.0
7551
7673
[SR- 7601 ]: < https: // bugs.swift.org/browse/SR-7601>
7552
7674
[SR- 7799 ]: < https: // bugs.swift.org/browse/SR-7799>
7553
7675
[SR- 8109 ]: < https: // bugs.swift.org/browse/SR-8109>
7676
+ [SR- 8546 ]: < https: // bugs.swift.org/browse/SR-8546>
7677
+ [SR- 9043 ]: < https: // bugs.swift.org/browse/SR-9043>
0 commit comments