File tree Expand file tree Collapse file tree 1 file changed +16
-12
lines changed Expand file tree Collapse file tree 1 file changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -850,6 +850,17 @@ struct ObjCBridgeMemo {
850
850
destBridgeWitness, targetBridgedType);
851
851
}
852
852
};
853
+
854
+ static const HashableWitnessTable* tryMemoizeNSStringHashableConformance (const Metadata *cls) {
855
+ auto nsString = getNSStringMetadata ();
856
+ do {
857
+ if (cls == nsString) {
858
+ return getNSStringHashableConformance ();
859
+ }
860
+ cls = _swift_class_getSuperclass (cls);
861
+ } while (cls != nullptr );
862
+ return nullptr ;
863
+ }
853
864
#endif
854
865
855
866
static DynamicCastResult
@@ -867,23 +878,16 @@ tryCastToAnyHashable(
867
878
const HashableWitnessTable *hashableConformance = nullptr ;
868
879
869
880
switch (srcType->getKind ()) {
881
+ case MetadataKind::Existential: {
882
+ return DynamicCastResult::Failure;
883
+ }
870
884
case MetadataKind::ForeignClass: // CF -> String
871
885
case MetadataKind::ObjCClassWrapper: { // Obj-C -> String
872
886
#if SWIFT_OBJC_INTEROP
873
- auto cls = srcType;
874
- auto nsString = getNSStringMetadata ();
875
- do {
876
- if (cls == nsString) {
877
- hashableConformance = getNSStringHashableConformance ();
878
- break ;
879
- }
880
- cls = _swift_class_getSuperclass (cls);
881
- } while (cls != nullptr );
882
- break ;
883
- #else
887
+ hashableConformance = tryMemoizeNSStringHashableConformance (srcType);
888
+ #endif
884
889
// If no Obj-C interop, just fall through to the general case.
885
890
break ;
886
- #endif
887
891
}
888
892
case MetadataKind::Optional: {
889
893
// FIXME: https://github.com/apple/swift/issues/51550
You can’t perform that action at this time.
0 commit comments