mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Protocols defined in Objective-C are mangled differently from Swift-defined protocols. Recognize this mangling and search for the appropriate Objective-C protocol using the Objective-C runtime.
37 lines
918 B
Swift
37 lines
918 B
Swift
// 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")!)
|
|
}
|
|
|
|
func f1_composition_NSCoding(_: NSCoding) { }
|
|
|
|
DemangleToMetadataTests.test("Objective-C protocols") {
|
|
expectEqual(type(of: f1_composition_NSCoding), _typeByMangledName("yySo8NSCoding_pc")!)
|
|
}
|
|
|
|
runAllTests()
|
|
|