@@ -25,9 +25,125 @@ 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
+
113
+ * [SE- 0242 ][]:
114
+
115
+ The memberwise initializer for structures now provide default values for variables that hold default expressions.
116
+
117
+ ```swift
118
+ struct Dog {
119
+ var name = " Generic dog name"
120
+ var age = 0
121
+
122
+ // The synthesized memberwise initializer
123
+ init (name : String = " Generic dog name" , age : Int = 0 )
124
+ }
125
+
126
+ let sparky = Dog (name : " Sparky" ) // Dog(name: "Sparky", age: 0)
127
+ ```
128
+
28
129
* [ SE-0068] [ ] :
29
130
30
- ` 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.
31
147
32
148
* [ SR-7799] [ ] :
33
149
@@ -46,12 +162,12 @@ Swift 5.1
46
162
}
47
163
```
48
164
49
- * ` weak ` and ` unowned ` variables can now be used inside types that
50
- declare ` Equatable ` or ` Hashable ` conformance.
165
+ * ` weak ` and ` unowned ` stored properties no longer inhibit the
166
+ automatic synthesis of ` Equatable ` or ` Hashable ` conformance.
51
167
52
168
* [ SR-2688] [ ] :
53
169
54
- An ` @autoclosure ` closure can now be a typealias.
170
+ An ` @autoclosure ` parameter can now be declared with a typealias type .
55
171
56
172
``` swift
57
173
class Foo {
@@ -62,10 +178,12 @@ Swift 5.1
62
178
63
179
* [ SR-7601] [ ] :
64
180
65
- Functions marked with ` @objc ` can now return ` Self `
181
+ Methods declared ` @objc ` inside a class can now return ` Self ` :
66
182
67
183
``` swift
68
- @objc func returnDynamicSelf () -> Self { return self }
184
+ class MyClass : NSObject {
185
+ @objc func clone () -> Self { return self }
186
+ }
69
187
```
70
188
71
189
* [ SR-2176] [ ] :
@@ -7511,6 +7629,7 @@ Swift 1.0
7511
7629
[SE- 0228 ]: < https: // github.com/apple/swift-evolution/blob/master/proposals/0228-fix-expressiblebystringinterpolation.md>
7512
7630
[SE- 0230 ]: < https: // github.com/apple/swift-evolution/blob/master/proposals/0230-flatten-optional-try.md>
7513
7631
[SE- 0235 ]: < https: // github.com/apple/swift-evolution/blob/master/proposals/0235-add-result.md>
7632
+ [SE- 0242 ]: < https: // github.com/apple/swift-evolution/blob/master/proposals/0242-default-values-memberwise.md>
7514
7633
[SE- 0245 ]: < https: // github.com/apple/swift-evolution/blob/master/proposals/0245-array-uninitialized-initializer.md>
7515
7634
7516
7635
[SR- 106 ]: < https: // bugs.swift.org/browse/SR-106>
@@ -7525,6 +7644,7 @@ Swift 1.0
7525
7644
[SR- 2388 ]: < https: // bugs.swift.org/browse/SR-2388>
7526
7645
[SR- 2394 ]: < https: // bugs.swift.org/browse/SR-2394>
7527
7646
[SR- 2608 ]: < https: // bugs.swift.org/browse/SR-2608>
7647
+ [SR- 2672 ]: < https: // bugs.swift.org/browse/SR-2672>
7528
7648
[SR- 2688 ]: < https: // bugs.swift.org/browse/SR-2688>
7529
7649
[SR- 4248 ]: < https: // bugs.swift.org/browse/SR-4248>
7530
7650
[SR- 5581 ]: < https: // bugs.swift.org/browse/SR-5581>
@@ -7534,3 +7654,5 @@ Swift 1.0
7534
7654
[SR- 7601 ]: < https: // bugs.swift.org/browse/SR-7601>
7535
7655
[SR- 7799 ]: < https: // bugs.swift.org/browse/SR-7799>
7536
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