mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This gives projects using C++ interop compat mode 5.9 access to the new features such as virtual methods and move-only types. rdar://126485814
57 lines
1.5 KiB
Swift
57 lines
1.5 KiB
Swift
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=swift-5.9)
|
|
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=swift-6)
|
|
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift)
|
|
|
|
// REQUIRES: executable_test
|
|
|
|
import StdlibUnittest
|
|
import VirtualMethods
|
|
|
|
var VirtualMethodsTestSuite = TestSuite("Virtual Methods")
|
|
|
|
VirtualMethodsTestSuite.test("value type") {
|
|
var d2 = Derived2()
|
|
expectEqual(42, d2.f())
|
|
|
|
var d3 = Derived3()
|
|
expectEqual(42, d3.f())
|
|
|
|
var d4 = Derived4()
|
|
expectEqual(24, d4.f())
|
|
|
|
let d5 = DerivedFromCallsPureMethod()
|
|
expectEqual(790, d5.getInt())
|
|
expectEqual(789, d5.getPureInt())
|
|
|
|
let d6 = DerivedFromDerivedFromCallsPureMethod()
|
|
expectEqual(790, d6.getInt())
|
|
expectEqual(789, d6.getPureInt())
|
|
}
|
|
|
|
if #available(SwiftStdlib 5.8, *) {
|
|
VirtualMethodsTestSuite.test("immortal reference type") {
|
|
let i = Immortal.create()
|
|
expectEqual(42, i.get42())
|
|
expectEqual(0, i.getIntValue())
|
|
|
|
let base = castToImmortalBase(i)
|
|
expectEqual(42, base.get42())
|
|
expectEqual(42, base.getOverridden42())
|
|
expectEqual(0, base.getIntValue())
|
|
|
|
i.setIntValue(566)
|
|
expectEqual(566, i.getIntValue())
|
|
expectEqual(566, base.getIntValue())
|
|
|
|
let d = DerivedFromImmortal.create()
|
|
expectEqual(42, d.get42())
|
|
expectEqual(42, d.getOverridden42())
|
|
d.setIntValue(321)
|
|
expectEqual(321, d.getIntValue())
|
|
let base2 = castToImmortalBase(castToImmortal(d))
|
|
expectEqual(321, base2.getIntValue())
|
|
}
|
|
}
|
|
|
|
runAllTests()
|