You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[5.4] Restore behavior of Optional -> AnyHashable casts
(This is a cherry-pick of PR swiftlang#35650 to the release/5.4 branch.)
The recent overhaul of the runtime dynamic casting made this
particular cast consistent with the compiler optimizer and with
how other similar casts behave. In particular, an `Optional`
is cast to `AnyHashable` by simple injection, whereas previously
the `Optional` was unwrapped (if it was non-nil) and the contents
were injected.
The previous behavior allowed code like the following to work:
```
let a: [String?:String] = ["Foo":"Bar"]
let b = a as [AnyHashable:Any]
print(b["Foo"] == "Bar") // Used to work
```
This is broken by the new cast behavior because `AnyHashable("Foo")`
is not considered equal to `AnyHashable("Foo" as String?)`.
Once SR-9047 is implemented, these two will in fact be considered
equal. At that time, we should go back to a simple injection to
make this cast behave identically to the compiler-optimized version
of this case.
Resolves rdar://73301155
0 commit comments