Commit 782f693
[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://733011551 parent cbdb032 commit 782f693
File tree
2 files changed
+85
-1
lines changed- stdlib/public/runtime
- test/Casting
2 files changed
+85
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
709 | 709 | | |
710 | 710 | | |
711 | 711 | | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
712 | 753 | | |
713 | | - | |
| 754 | + | |
714 | 755 | | |
715 | 756 | | |
716 | 757 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
881 | 881 | | |
882 | 882 | | |
883 | 883 | | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
884 | 927 | | |
0 commit comments