mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Only works for trivial types right now because features related to initialization and deinitialization are seriously busted.
60 lines
1.6 KiB
Swift
60 lines
1.6 KiB
Swift
// RUN: %target-run-simple-swift(-import-objc-header %S/Inputs/objc_implementation.h -D TOP_LEVEL_CODE -swift-version 5) %s | %FileCheck %s
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: objc_interop
|
|
|
|
import Foundation
|
|
|
|
@_objcImplementation extension ImplClass {
|
|
@objc override init() {
|
|
self.implProperty = 0
|
|
super.init()
|
|
}
|
|
|
|
@objc var implProperty: Int
|
|
|
|
@objc class func runTests() {
|
|
let impl = ImplClass()
|
|
print("someMethod =", impl.someMethod())
|
|
print("implProperty =", impl.implProperty)
|
|
impl.implProperty = 42
|
|
print("implProperty =", impl.implProperty)
|
|
|
|
let swiftSub = SwiftSubclass()
|
|
print("someMethod =", swiftSub.someMethod())
|
|
print("implProperty =", swiftSub.implProperty)
|
|
swiftSub.implProperty = 42
|
|
print("implProperty =", swiftSub.implProperty)
|
|
|
|
print("otherProperty =", swiftSub.otherProperty)
|
|
swiftSub.otherProperty = 13
|
|
print("otherProperty =", swiftSub.otherProperty)
|
|
print("implProperty =", swiftSub.implProperty)
|
|
}
|
|
|
|
@objc func someMethod() -> String { "ImplClass.someMethod()" }
|
|
}
|
|
|
|
class SwiftSubclass: ImplClass {
|
|
@objc var otherProperty: Int = 1
|
|
|
|
override init() {
|
|
super.init()
|
|
}
|
|
|
|
override func someMethod() -> String { "SwiftSubclass.someMethod()" }
|
|
}
|
|
|
|
// `#if swift` to ignore the inactive branch's contents
|
|
#if swift(>=5.0) && TOP_LEVEL_CODE
|
|
ImplClass.runTests()
|
|
// CHECK: someMethod = ImplClass.someMethod()
|
|
// CHECK: implProperty = 0
|
|
// CHECK: implProperty = 42
|
|
// CHECK: someMethod = SwiftSubclass.someMethod()
|
|
// CHECK: implProperty = 0
|
|
// CHECK: implProperty = 42
|
|
// CHECK: otherProperty = 1
|
|
// CHECK: otherProperty = 13
|
|
// CHECK: implProperty = 42
|
|
#endif
|