mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
As part of this, rename TypeMetadataRecordKind to TypeReferenceKind and consistently give it three bits of storage. The better modelling of these type references appears to have been sufficient to make dynamic conformance checks succeed, which is good but unexpected.
74 lines
2.0 KiB
Swift
74 lines
2.0 KiB
Swift
// RUN: %empty-directory(%t)
|
|
|
|
// RUN: %target-clang %target-cc-options -isysroot %sdk -fobjc-arc %S/Inputs/objc_runtime_visible.m -fmodules -nodefaultlibs -lc -dynamiclib -o %t/libobjc_runtime_visible.dylib -install_name @executable_path/libobjc_runtime_visible.dylib
|
|
// RUN: %target-codesign %t/libobjc_runtime_visible.dylib
|
|
// RUN: nm -g %t/libobjc_runtime_visible.dylib | %FileCheck %s
|
|
// RUN: %target-build-swift -import-objc-header %S/Inputs/objc_runtime_visible.h %t/libobjc_runtime_visible.dylib %s -o %t/main
|
|
// RUN: %target-run %t/main %t/libobjc_runtime_visible.dylib
|
|
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: objc_interop
|
|
|
|
// CHECK-NOT: HiddenClass
|
|
|
|
import Foundation
|
|
import StdlibUnittest
|
|
|
|
extension HiddenClass {
|
|
class func create() -> HiddenClass {
|
|
return createHidden()
|
|
}
|
|
|
|
func normalMethod() -> String {
|
|
return self.name
|
|
}
|
|
}
|
|
|
|
var ObjCRuntimeVisibleTestSuite = TestSuite("ObjCRuntimeVisible")
|
|
|
|
ObjCRuntimeVisibleTestSuite.test("methods") {
|
|
let obj = HiddenClass.create()
|
|
expectEqual("Beatrice", obj.name)
|
|
expectEqual("Beatrice", obj.normalMethod())
|
|
}
|
|
|
|
protocol SwiftProto {
|
|
func doTheThing() -> AnyObject
|
|
}
|
|
extension HiddenClass: SwiftProto {
|
|
func doTheThing() -> AnyObject { return self }
|
|
}
|
|
|
|
func callTheThing<T: SwiftProto>(_ instance: T) -> AnyObject {
|
|
return instance.doTheThing()
|
|
}
|
|
|
|
ObjCRuntimeVisibleTestSuite.test("downcast") {
|
|
let obj = HiddenClass.create()
|
|
let opaque: AnyObject = obj
|
|
let downcasted = opaque as? HiddenClass
|
|
expectNotNil(downcasted)
|
|
expectTrue(obj === downcasted)
|
|
}
|
|
|
|
ObjCRuntimeVisibleTestSuite.test("protocols") {
|
|
let obj = HiddenClass.create()
|
|
expectTrue(obj === obj.doTheThing())
|
|
|
|
let protoObj: SwiftProto = obj
|
|
expectTrue(obj === protoObj.doTheThing())
|
|
|
|
expectTrue(obj === callTheThing(obj))
|
|
}
|
|
|
|
ObjCRuntimeVisibleTestSuite.test("protocols/downcast")
|
|
.code {
|
|
let obj = HiddenClass.create()
|
|
let opaque: AnyObject = obj
|
|
let downcasted = opaque as? SwiftProto
|
|
expectNotNil(downcasted)
|
|
expectTrue(obj === downcasted!.doTheThing())
|
|
}
|
|
|
|
runAllTests()
|