Skip to content

Commit f651afe

Browse files
authored
Merge pull request #65887 from hamishknight/changelog
2 parents c7eda8a + 258ecbf commit f651afe

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

CHANGELOG.md

+34
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,39 @@
55
66
## Swift 5.9
77

8+
* [SE-0380][]:
9+
10+
`if` and `switch` statements may now be used as expressions to:
11+
12+
* Return values from functions, properties, and closures (either with
13+
implicit or explicit `return`)
14+
* Throw errors using `throw`
15+
* Assign values to variables
16+
* Declare variables
17+
18+
Each branch of the `if` or `switch` must be a single expression, the value
19+
of which becomes the value of the overall expression when that branch is
20+
chosen.
21+
22+
```swift
23+
let bullet =
24+
if isRoot && (count == 0 || !willExpand) { "" }
25+
else if count == 0 { "- " }
26+
else if maxDepth <= 0 { "" }
27+
else { "" }
28+
```
29+
30+
```swift
31+
public static func width(_ x: Unicode.Scalar) -> Int {
32+
switch x.value {
33+
case 0..<0x80: 1
34+
case 0x80..<0x0800: 2
35+
case 0x0800..<0x1_0000: 3
36+
default: 4
37+
}
38+
}
39+
```
40+
841
* [#64927][]:
942

1043
Swift 5.9 introduces warnings that catch conversions from an inout
@@ -9732,6 +9765,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
97329765
[SE-0370]: <https://github.com/apple/swift-evolution/blob/main/proposals/0370-pointer-family-initialization-improvements.md>
97339766
[SE-0376]: <https://github.com/apple/swift-evolution/blob/main/proposals/0376-function-back-deployment.md>
97349767
[SE-0377]: <https://github.com/apple/swift-evolution/blob/main/proposals/0377-parameter-ownership-modifiers.md>
9768+
[SE-0380]: <https://github.com/apple/swift-evolution/blob/main/proposals/0380-if-switch-expressions.md>
97359769

97369770
[#64927]: <https://github.com/apple/swift/issues/64927>
97379771
[#42697]: <https://github.com/apple/swift/issues/42697>

0 commit comments

Comments
 (0)