File: complete_init.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 (142 lines) | stat: -rw-r--r-- 4,353 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/mods)
// RUN: %empty-directory(%t/co-same)
// RUN: %empty-directory(%t/co-across)
// RUN: split-file %s %t --leading-lines

// Completion in the current file/module
// RUN: %target-swift-ide-test -batch-code-completion -code-complete-inits-in-postfix-expr -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t/co-same

// Completion across modules
// RUN: %target-swift-frontend -emit-module %t/InitTypes.swift -o %t/mods/
// RUN: %target-swift-ide-test -batch-code-completion -code-complete-inits-in-postfix-expr -source-filename %t/InitUses.swift -filecheck %raw-FileCheck -completion-output-dir %t/co-across -I %t/mods -D SEPARATED

//--- InitTypes.swift
public struct A {
  public init() {}
}

public struct B {
  let x: A, y: A, z: A
  public init(x: A, y: A, z: A) {
    self.x = x
    self.y = y
    self.z = z
  }
}

public struct C {
  public init() {}
  public init(x: A) {}
  public init(y: A=A()) {}
}

public class D {
  public init() {}
}
public class E {
  public init(x: A) {}
}

public class F : E {
  // inherited init(x: A)
  public convenience init() {
    self.init(x: A())
  }
}

public protocol G {
  init(x: A)
}

public struct H : G {
  public init(x: A) {}
}

public protocol I : G {
  init(y: A)
}

public typealias J = A

public struct K {
  public typealias X = A
  public struct Y {
    public init() {}
  }
}

public struct L<X: G> {
  public typealias Y = X
}

//--- InitUses.swift
#if SEPARATED
import InitTypes
#endif

func testTopLevel() {
  #^TOP_LEVEL_0?check=TOP_LEVEL_0;check=NEGATIVE_TOP_LEVEL_0^#
}
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}:    A()[#A#]{{; name=.+}}
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}:    B({#x: A#}, {#y: A#}, {#z: A#})[#B#]{{; name=.+}}
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}:    C()[#C#]{{; name=.+}}
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}:    C({#x: A#})[#C#]{{; name=.+}}
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}:    C({#y: A#})[#C#]{{; name=.+}}
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}:    D()[#D#]{{; name=.+}}
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}:    E({#x: A#})[#E#]{{; name=.+}}
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}:    F({#x: A#})[#F#]{{; name=.+}}
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}:    F()[#F#]{{; name=.+}}
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}:    H({#x: A#})[#H#]{{; name=.+}}
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}:    J()[#A#]{{; name=.+}}
// NEGATIVE_TOP_LEVEL_0-NOT: Decl[Constructor]/{{.*}}:    E()
// NEGATIVE_TOP_LEVEL_0-NOT: Decl[Constructor]/{{.*}}:    G(
// NEGATIVE_TOP_LEVEL_0-NOT: Decl[Constructor]/{{.*}}:    I(

func testQualified0() {
  K.#^K_QUALIFIED_0^#
}
// K_QUALIFIED_0-DAG: Decl[Constructor]/CurrNominal:    X()[#A#]{{; name=.+}}
// K_QUALIFIED_0-DAG: Decl[Constructor]/CurrNominal:    Y()[#K.Y#]{{; name=.+}}

func testQualified1() {
  L.#^L_QUALIFIED_0^#
}
// L_QUALIFIED_0-NOT: X({#x: A#})
// L_QUALIFIED_0-DAG: Decl[Constructor]/CurrNominal:    Y({#x: A#})[#G#]{{; name=.+}}

func testGenericParam<T: I, U: G>() {
  #^TOP_LEVEL_1?check=TOP_LEVEL_0;check=GENERIC_PARAM_0^#
}
// GENERIC_PARAM_0-DAG: Decl[Constructor]/Local:    T({#x: A#})[#I#]{{; name=.+}}
// GENERIC_PARAM_0-DAG: Decl[Constructor]/Local:    T({#y: A#})[#I#]{{; name=.+}}
// GENERIC_PARAM_0-DAG: Decl[Constructor]/Local:    U({#x: A#})[#G#]{{; name=.+}}
// GENERIC_PARAM_0-NOT: Decl[Constructor]/Local:    U({#y

extension L {
  func test() {
    #^INSIDE_L_0^#
  }
}
// INSIDE_L_0-DAG: Decl[Constructor]/CurrNominal:    Y({#x: A#})[#G#]{{; name=.+}}

// FIXME: <rdar://problem/20530021> Code complete generic parameters in extensions
// INSIDE_L_0-DAG: Decl[GenericTypeParam]/Local:     X[#X#]; name=X
// INSIDE_L_0-DAG: Decl[Constructor]/Local:          X({#x: A#})[#G#]{{; name=.+}}


struct M<X: G> {
  typealias Y = X
  func test() {
    #^INSIDE_M_0^#
  }
}
// INSIDE_M_0-DAG: Decl[Constructor]/CurrNominal:    Y({#x: A#})[#G#]{{; name=.+}}
// INSIDE_M_0-DAG: Decl[Constructor]/Local:          X({#x: A#})[#G#]{{; name=.+}}

typealias CAlias = C

var CAliasInstance = CAlias(#^ALIAS_CONSTRUCTOR_0^#
// rdar://18586415
// ALIAS_CONSTRUCTOR_0: Decl[Constructor]/CurrNominal/Flair[ArgLabels]:      ['(']{#x: A#}[')'][#CAlias#];
// ALIAS_CONSTRUCTOR_0: Decl[Constructor]/CurrNominal/Flair[ArgLabels]:      ['(']{#y: A#}[')'][#CAlias#];