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