Skip to content

Commit 0acd423

Browse files
authored
[Changelog] Add changelog entry for SE-0380 (#65888)
1 parent c69be5c commit 0acd423

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,39 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
44

55
## Swift 5.9
66

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+
740
* [#64927][]:
841

942
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
97299762
[SE-0370]: <https://github.com/apple/swift-evolution/blob/main/proposals/0370-pointer-family-initialization-improvements.md>
97309763
[SE-0376]: <https://github.com/apple/swift-evolution/blob/main/proposals/0376-function-back-deployment.md>
97319764
[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>
97329766

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

0 commit comments

Comments
 (0)