mirror of
https://github.com/apple/swift.git
synced 2026-06-27 12:25:55 +02:00
800e3818b7
@objc protocols don't have witness tables. However, both type metadata (in the nominal type descriptors) and the runtime code to demangle type names into metadata weren't acknowledging this. Fix type metadata emission to not count an "extra argument" for @objc protocol conformance requirements, and teach the runtime code to properly look for conformances to @objc protocols (through the Objective-C runtime) and not record witness tables for them.
79 lines
2.1 KiB
Swift
79 lines
2.1 KiB
Swift
// RUN: %target-run-simple-swift
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: objc_interop
|
|
|
|
import StdlibUnittest
|
|
import Foundation
|
|
import CoreFoundation
|
|
|
|
let DemangleToMetadataTests = TestSuite("DemangleToMetadataObjC")
|
|
|
|
@objc class C : NSObject { }
|
|
@objc enum E: Int { case a }
|
|
@objc protocol P1 { }
|
|
protocol P2 { }
|
|
|
|
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")!)
|
|
}
|
|
|
|
DemangleToMetadataTests.test("Objective-C classes") {
|
|
expectEqual(type(of: NSObject()), _typeByMangledName("So8NSObjectC")!)
|
|
}
|
|
|
|
func f1_composition_NSCoding(_: NSCoding) { }
|
|
|
|
DemangleToMetadataTests.test("Objective-C protocols") {
|
|
expectEqual(type(of: f1_composition_NSCoding), _typeByMangledName("yySo8NSCoding_pc")!)
|
|
}
|
|
|
|
DemangleToMetadataTests.test("Classes that don't exist") {
|
|
expectNil(_typeByMangledName("4main4BoomC"))
|
|
}
|
|
|
|
DemangleToMetadataTests.test("CoreFoundation classes") {
|
|
expectEqual(CFArray.self, _typeByMangledName("So10CFArrayRefa")!)
|
|
}
|
|
|
|
DemangleToMetadataTests.test("Imported error types") {
|
|
expectEqual(URLError.self, _typeByMangledName("10Foundation8URLErrorV")!)
|
|
expectEqual(URLError.Code.self,
|
|
_typeByMangledName("10Foundation8URLErrorV4CodeV")!)
|
|
}
|
|
|
|
DemangleToMetadataTests.test("Imported swift_wrapper types") {
|
|
expectEqual(URLFileResourceType.self,
|
|
_typeByMangledName("So21NSURLFileResourceTypea")!)
|
|
}
|
|
|
|
DemangleToMetadataTests.test("Imported enum types") {
|
|
expectEqual(NSURLSessionTask.State.self,
|
|
_typeByMangledName("So21NSURLSessionTaskStateV")!)
|
|
}
|
|
|
|
class CG4<T: P1, U: P2> { }
|
|
extension C : P1 { }
|
|
extension C : P2 { }
|
|
|
|
class D: P2 { }
|
|
|
|
DemangleToMetadataTests.test("@objc protocol conformances") {
|
|
expectEqual(CG4<C, C>.self,
|
|
_typeByMangledName("4main3CG4CyAA1CCAA1CCG")!)
|
|
expectNil(_typeByMangledName("4main3CG4CyAA1DCAA1DCG"))
|
|
}
|
|
|
|
runAllTests()
|
|
|