Skip to content

Commit bbfed7d

Browse files
committed
Add changelog entry for optional-to-archetype casting behaviour change
1 parent 2e2e8f0 commit bbfed7d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,28 @@ CHANGELOG
2424
Swift 5.0
2525
---------
2626

27+
* [SR-4248][]:
28+
29+
In Swift 5 mode, when casting an optional value to a generic placeholder type,
30+
the compiler will be more conservative with the unwrapping of the value. The
31+
result of such a cast now matches the result you would get in a non-generic
32+
context.
33+
34+
For example:
35+
```swift
36+
func forceCast<U>(_ value: Any?, to type: U.Type) -> U {
37+
return value as! U
38+
}
39+
40+
let value: Any? = 42
41+
print(forceCast(value, to: Any.self))
42+
// prints: Optional(42)
43+
// (prior to Swift 5, this would print: 42)
44+
45+
print(value as! Any)
46+
// prints: Optional(42)
47+
```
48+
2749
* [SE-0214][]:
2850

2951
Renamed the `DictionaryLiteral` type to `KeyValuePairs`.
@@ -7176,3 +7198,4 @@ Swift 1.0
71767198
[SR-2388]: <https://bugs.swift.org/browse/SR-2388>
71777199
[SR-2394]: <https://bugs.swift.org/browse/SR-2394>
71787200
[SR-2608]: <https://bugs.swift.org/browse/SR-2608>
7201+
[SR-4248]: <https://bugs.swift.org/browse/SR-4248>

0 commit comments

Comments
 (0)