File: inherited-defaults-execution.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (51 lines) | stat: -rw-r--r-- 2,001 bytes parent folder | download
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

public class Base {
  public let x: Int
  public let y: Int
  public init(x: Int = 45, y: Int = 98) {
    self.x = x
    self.y = y
  }
}
public class Derived: Base {}