mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Runtime] Use the old remangler to compute the @objc protocol name.
The “old” mangling that is used for runtime names of @objc protocols uses a simpler substitution scheme, so you can’t simply take a mangled name from the new mangling and fix up the ends. Fixes rdar://problem/45685649.
This commit is contained in:
@@ -946,8 +946,7 @@ public:
|
||||
#if SWIFT_OBJC_INTEROP
|
||||
// Look for a Swift-defined @objc protocol with the Swift 3 mangling that
|
||||
// is used for Objective-C entities.
|
||||
std::string objcMangledName =
|
||||
"_TtP" + mangledName.substr(0, mangledName.size()-1) + "_";
|
||||
std::string objcMangledName = "_Tt" + mangleNodeOld(node) + "_";
|
||||
if (auto protocol = objc_getProtocol(objcMangledName.c_str()))
|
||||
return ProtocolDescriptorRef::forObjC(protocol);
|
||||
#endif
|
||||
|
||||
@@ -15,6 +15,7 @@ let DemangleToMetadataTests = TestSuite("DemangleToMetadataObjC")
|
||||
@objc protocol P1 { }
|
||||
protocol P2 { }
|
||||
@objc protocol P3: P1 { }
|
||||
@objc protocol mainP4 { }
|
||||
|
||||
DemangleToMetadataTests.test("@objc classes") {
|
||||
expectEqual(type(of: C()), _typeByMangledName("4main1CC")!)
|
||||
@@ -25,10 +26,13 @@ DemangleToMetadataTests.test("@objc enums") {
|
||||
}
|
||||
|
||||
func f1_composition_objc_protocol(_: P1) { }
|
||||
func f1_composition_objc_protocol_P4(_: mainP4) { }
|
||||
|
||||
DemangleToMetadataTests.test("@objc protocols") {
|
||||
expectEqual(type(of: f1_composition_objc_protocol),
|
||||
_typeByMangledName("yy4main2P1_pc")!)
|
||||
expectEqual(type(of: f1_composition_objc_protocol_P4),
|
||||
_typeByMangledName("yy4main0A2P4_pc")!)
|
||||
}
|
||||
|
||||
DemangleToMetadataTests.test("Objective-C classes") {
|
||||
|
||||
Reference in New Issue
Block a user