@@ -4,6 +4,39 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
4
4
5
5
## Swift 5.9
6
6
7
+ * [SE-0380][]:
8
+
9
+ `if` and `switch` statements may now be used as expressions to:
10
+
11
+ * Return values from functions, properties, and closures (either with
12
+ implicit or explicit `return`)
13
+ * Throw errors using `throw`
14
+ * Assign values to variables
15
+ * Declare variables
16
+
17
+ Each branch of the `if` or `switch` must be a single expression, the value
18
+ of which becomes the value of the overall expression when that branch is
19
+ chosen.
20
+
21
+ ```swift
22
+ let bullet =
23
+ if isRoot && (count == 0 || !willExpand) { "" }
24
+ else if count == 0 { "- " }
25
+ else if maxDepth <= 0 { "▹ " }
26
+ else { "▿ " }
27
+ ```
28
+
29
+ ```swift
30
+ public static func width(_ x: Unicode.Scalar) -> Int {
31
+ switch x.value {
32
+ case 0..<0x80: 1
33
+ case 0x80..<0x0800: 2
34
+ case 0x0800..<0x1_0000: 3
35
+ default: 4
36
+ }
37
+ }
38
+ ```
39
+
7
40
* [#64927][]:
8
41
9
42
Swift 5.9 introduces warnings that catch conversions from an inout
@@ -9729,6 +9762,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
9729
9762
[SE-0370]: <https://github.com/apple/swift-evolution/blob/main/proposals/0370-pointer-family-initialization-improvements.md>
9730
9763
[SE-0376]: <https://github.com/apple/swift-evolution/blob/main/proposals/0376-function-back-deployment.md>
9731
9764
[SE-0377]: <https://github.com/apple/swift-evolution/blob/main/proposals/0377-parameter-ownership-modifiers.md>
9765
+ [SE-0380]: <https://github.com/apple/swift-evolution/blob/main/proposals/0380-if-switch-expressions.md>
9732
9766
9733
9767
[#64927]: <https://github.com/apple/swift/issues/64927>
9734
9768
[#42697]: <https://github.com/apple/swift/issues/42697>
0 commit comments