Skip to content

Commit 41d5cb0

Browse files
authored
Merge pull request #24080 from slavapestov/update-changelog-md
Update CHANGELOG.md
2 parents 09da304 + 6b5b4b4 commit 41d5cb0

File tree

1 file changed

+130
-6
lines changed

1 file changed

+130
-6
lines changed

CHANGELOG.md

Lines changed: 130 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
| Contents |
88
| :--------------------- |
9+
| [Swift Next](#swift-next) |
910
| [Swift 5.1](#swift-51) |
1011
| [Swift 5.0](#swift-50) |
1112
| [Swift 4.2](#swift-42) |
@@ -22,9 +23,112 @@ CHANGELOG
2223

2324
</details>
2425

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+
2544
Swift 5.1
2645
---------
2746

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+
28132
* [SE-0242][]:
29133

30134
The memberwise initializer for structures now provide default values for variables that hold default expressions.
@@ -43,7 +147,22 @@ Swift 5.1
43147

44148
* [SE-0068][]:
45149

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.
47166

48167
* [SR-7799][]:
49168

@@ -62,12 +181,12 @@ Swift 5.1
62181
}
63182
```
64183

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.
67186

68187
* [SR-2688][]:
69188

70-
An `@autoclosure` closure can now be a typealias.
189+
An `@autoclosure` parameter can now be declared with a typealias type.
71190

72191
```swift
73192
class Foo {
@@ -78,10 +197,12 @@ Swift 5.1
78197

79198
* [SR-7601][]:
80199

81-
Functions marked with `@objc` can now return `Self`
200+
Methods declared `@objc` inside a class can now return `Self`:
82201

83202
```swift
84-
@objc func returnDynamicSelf() -> Self { return self }
203+
class MyClass : NSObject {
204+
@objc func clone() -> Self { return self }
205+
}
85206
```
86207

87208
* [SR-2176][]:
@@ -7542,6 +7663,7 @@ Swift 1.0
75427663
[SR-2388]: <https://bugs.swift.org/browse/SR-2388>
75437664
[SR-2394]: <https://bugs.swift.org/browse/SR-2394>
75447665
[SR-2608]: <https://bugs.swift.org/browse/SR-2608>
7666+
[SR-2672]: <https://bugs.swift.org/browse/SR-2672>
75457667
[SR-2688]: <https://bugs.swift.org/browse/SR-2688>
75467668
[SR-4248]: <https://bugs.swift.org/browse/SR-4248>
75477669
[SR-5581]: <https://bugs.swift.org/browse/SR-5581>
@@ -7551,3 +7673,5 @@ Swift 1.0
75517673
[SR-7601]: <https://bugs.swift.org/browse/SR-7601>
75527674
[SR-7799]: <https://bugs.swift.org/browse/SR-7799>
75537675
[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

Comments
 (0)