mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Runtime] Lookup @objc protocols in mangled name -> type metadata function.
Swift-defined @objc protocols are registered with the Objective-C runtime under the Swift 3 mangling scheme; look in the Objective-C runting using objc_getProtocol() with the appropriate name. Also, correctly compute the "class bound" bit when forming a protocol composition metatype. The information isn't in the mangled name when it can be recovered from the protocols themselves, so look at the protocols.
This commit is contained in:
30
test/Runtime/demangleToMetadataObjC.swift
Normal file
30
test/Runtime/demangleToMetadataObjC.swift
Normal file
@@ -0,0 +1,30 @@
|
||||
// RUN: %target-run-simple-swift
|
||||
// REQUIRES: executable_test
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
import StdlibUnittest
|
||||
import Foundation
|
||||
|
||||
let DemangleToMetadataTests = TestSuite("DemangleToMetadataObjC")
|
||||
|
||||
@objc class C : NSObject { }
|
||||
@objc enum E: Int { case a }
|
||||
@objc protocol P1 { }
|
||||
|
||||
DemangleToMetadataTests.test("@objc classes") {
|
||||
expectEqual(type(of: C()), _typeByMangledName("4main1CC")!)
|
||||
}
|
||||
|
||||
DemangleToMetadataTests.test("@objc enums") {
|
||||
expectEqual(type(of: E.a), _typeByMangledName("4main1EO")!)
|
||||
}
|
||||
|
||||
func f1_composition_objc_protocol(_: P1) { }
|
||||
|
||||
DemangleToMetadataTests.test("@objc protocols") {
|
||||
expectEqual(type(of: f1_composition_objc_protocol),
|
||||
_typeByMangledName("yy4main2P1_pc")!)
|
||||
}
|
||||
|
||||
runAllTests()
|
||||
|
||||
Reference in New Issue
Block a user