File: default-args.swift

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (62 lines) | stat: -rw-r--r-- 2,406 bytes parent folder | download | duplicates (2)
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
52
53
54
55
56
57
58
59
60
61
62
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t/Test~partial.swiftmodule -module-name Test -primary-file %s
// RUN: %target-swift-frontend -merge-modules -emit-module -o %t/Test.swiftmodule %t/Test~partial.swiftmodule
// RUN: %target-swift-ide-test -print-module -module-to-print=Test -source-filename=x -I %t -prefer-type-repr=false -fully-qualified-types=true | %FileCheck %s

// RUN: %target-swift-frontend -typecheck -emit-module-interface-path %t/Test.swiftinterface -module-name Test -enable-library-evolution %s
// RUN: rm %t/Test.swiftmodule
// RUN: echo "import Test" > %t/test-client.swift
// RUN: %target-swift-frontend -typecheck -I%t %t/test-client.swift
// RUN: %FileCheck %s < %t/Test.swiftinterface

// CHECK: class Base {
public class Base {
  // CHECK: init(x: Swift.Int = 3)
  public init(x: Int = 3) {}
  public convenience init(convInit: Int) {
    self.init(x: convInit)
  }
  // CHECK: foo(y: Swift.Int = 42)
  public func foo(y: Int = 42) {}
}

// CHECK: class Derived : Test.Base {
public class Derived: Base {
  // CHECK: init(y: Swift.Int)
  public convenience init(y: Int) {
    self.init()
  }

  // CHECK-NOT: init(convInit: Swift.Int = super)
  // CHECK: override {{(public )?}}init(x: Swift.Int = super)
  // CHECK-NOT: init(convInit: Swift.Int = super)
}

public enum Enum {
  // CHECK: case pie(filling: Swift.String = "apple")
  case pie(filling: String = "apple")
}

public struct HasSubscript {
  // CHECK: subscript(x: Swift.Int = 0) -> Swift.Int {
  public subscript(x: Int = 0) -> Int { return 0 }
}

// CHECK: func hasClosureDefaultArg(_ x: () -> Swift.Void = {
// CHECK-NEXT: })
public func hasClosureDefaultArg(_ x: () -> Void = {
}) {
}

// CHECK: func hasMagicDefaultArgs(_ f: Swift.String = #file, _ fu: Swift.String = #function, _ l: Swift.Int = #line)
public func hasMagicDefaultArgs(_ f: String = #file, _ fu: String = #function, _ l: Int = #line) {}

// CHECK: func hasSimpleDefaultArgs(_ x: Swift.Int = 0, b: Swift.Int = 1)
public func hasSimpleDefaultArgs(_ x: Int = 0, b: Int = 1) {
}

// rdar://83202870
// https://github.com/apple/swift/issues/57504
// Make sure we can extract the textual representation here.
// CHECK: func hasTupleConstructionDefaultArgs(_ x: Any = (), y: (Swift.String, Swift.Int) = ("", 0))
public func hasTupleConstructionDefaultArgs(_ x: Any = Void(), y: (String, Int) = (String, Int)("", 0)) {}