|
| 1 | +// REQUIRES: executable_test |
| 2 | +// RUN: %empty-directory(%t) |
| 3 | + |
| 4 | +// 1) Build the 'Inherited' library and its interface from this file |
| 5 | +// |
| 6 | +// RUN: %target-build-swift-dylib(%t/%target-library-name(Inherited)) -emit-module-path %t/Inherited.swiftmodule -emit-parseable-module-interface-path %t/Inherited.swiftinterface -module-name Inherited %s |
| 7 | +// RUN: rm %t/Inherited.swiftmodule |
| 8 | + |
| 9 | +// 2) Check the interface includes the synthesized initializers of the base |
| 10 | +// class in the derived class explicitly and uses the '= super' syntax to |
| 11 | +// inherit its default arguments. |
| 12 | +// |
| 13 | +// RUN: cat %t/Inherited.swiftinterface | %FileCheck --check-prefix=INTERFACE %s |
| 14 | +// |
| 15 | +// INTERFACE: public class Base { |
| 16 | +// INTERFACE: public init(x: Swift.Int = 45, y: Swift.Int = 98) |
| 17 | +// INTERFACE: } |
| 18 | +// INTERFACE: public class Derived : Inherited.Base { |
| 19 | +// INTERFACE: override public init(x: Swift.Int = super, y: Swift.Int = super) |
| 20 | +// INTERFACE: } |
| 21 | + |
| 22 | +// 4) Generate a main.swift file that uses the 'Inherited' library and makes use |
| 23 | +// of the inherited default arguments |
| 24 | +// |
| 25 | +// RUN: echo "import Inherited" > %t/main.swift |
| 26 | +// RUN: echo "print(Derived().x)" >> %t/main.swift |
| 27 | +// RUN: echo "print(Derived().y)" >> %t/main.swift |
| 28 | + |
| 29 | +// 5) Build and run the executable, checking the defaulted arguments resulted in |
| 30 | +// the correct values being stored |
| 31 | +// |
| 32 | +// RUN: %target-build-swift -I%t -L%t -lInherited -o %t/main %target-rpath(%t) %t/main.swift -swift-version 5 |
| 33 | +// RUN: %target-codesign %t/main %t/%target-library-name(Inherited) |
| 34 | +// RUN: %target-run %t/main | %FileCheck --check-prefix=OUTPUT %s |
| 35 | +// |
| 36 | +// OUTPUT: 45 |
| 37 | +// OUTPUT-NEXT: 98 |
| 38 | + |
| 39 | +public class Base { |
| 40 | + public let x: Int |
| 41 | + public let y: Int |
| 42 | + public init(x: Int = 45, y: Int = 98) { |
| 43 | + self.x = x |
| 44 | + self.y = y |
| 45 | + } |
| 46 | +} |
| 47 | +public class Derived: Base {} |
0 commit comments