- Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathinherited-defaults-execution.swift
51 lines (45 loc) · 1.95 KB
/
inherited-defaults-execution.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// REQUIRES: executable_test
// RUN: %empty-directory(%t)
// UNSUPPORTED: swift_test_mode_optimize_none_with_implicit_dynamic
// UNSUPPORTED: swift_test_mode_optimize_with_implicit_dynamic
// 1) Build the 'Inherited' library and its interface from this file
//
// RUN: %target-build-swift-dylib(%t/%target-library-name(Inherited)) -emit-module-path %t/Inherited.swiftmodule -emit-module-interface-path %t/Inherited.swiftinterface -module-name Inherited %s
// RUN: rm %t/Inherited.swiftmodule
// RUN: %target-swift-typecheck-module-from-interface(%t/Inherited.swiftinterface)
// 2) Check the interface includes the synthesized initializers of the base
// class in the derived class explicitly and uses the '= super' syntax to
// inherit its default arguments.
//
// RUN: %FileCheck --check-prefix=INTERFACE %s < %t/Inherited.swiftinterface
//
// INTERFACE: public class Base {
// INTERFACE: public init(x: Swift.Int = 45, y: Swift.Int = 98)
// INTERFACE: }
// INTERFACE: public class Derived : Inherited.Base {
// INTERFACE: override public init(x: Swift.Int = super, y: Swift.Int = super)
// INTERFACE: }
// 4) Generate a main.swift file that uses the 'Inherited' library and makes use
// of the inherited default arguments
//
// RUN: echo "import Inherited" > %t/main.swift
// RUN: echo "print(Derived().x)" >> %t/main.swift
// RUN: echo "print(Derived().y)" >> %t/main.swift
// 5) Build and run the executable, checking the defaulted arguments resulted in
// the correct values being stored
//
// RUN: %target-build-swift -I%t -L%t -lInherited -o %t/main %target-rpath(%t) %t/main.swift -swift-version 5
// RUN: %target-codesign %t/main %t/%target-library-name(Inherited)
// RUN: %target-run %t/main %t/%target-library-name(Inherited) | %FileCheck --check-prefix=OUTPUT %s
//
// OUTPUT: 45
// OUTPUT-NEXT: 98
publicclassBase{
publicletx:Int
publiclety:Int
publicinit(x:Int=45, y:Int=98){
self.x = x
self.y = y
}
}
publicclassDerived:Base{}