Skip to content

Commit 337f91c

Browse files
committed
[Variadic Generics] Update tests for syntax changes.
1 parent bcceea2 commit 337f91c

20 files changed

+206
-206
lines changed

test/Constraints/pack-expansion-expressions.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,43 @@
22

33
// REQUIRES: asserts
44

5-
func tuplify<T...>(_ t: T...) -> (T...) {
5+
func tuplify<T...>(_ t: repeat each T) -> (repeat each T) {
66
return (repeat each t)
77
}
88

9-
func prepend<First, Rest...>(value: First, to rest: Rest...) -> (First, Rest...) {
9+
func prepend<First, Rest...>(value: First, to rest: repeat each Rest) -> (First, repeat each Rest) {
1010
return (value, repeat each rest)
1111
}
1212

13-
func concatenate<T..., U...>(_ first: T..., with second: U...) -> (T..., U...) {
13+
func concatenate<T..., U...>(_ first: repeat each T, with second: repeat each U) -> (repeat each T, repeat each U) {
1414
return (repeat each first, repeat each second)
1515
}
1616

17-
func zip<T..., U...>(_ first: T..., with second: U...) -> ((T, U)...) {
17+
func zip<T..., U...>(_ first: repeat each T, with second: repeat each U) -> (repeat (each T, each U)) {
1818
return (repeat (each first, each second))
1919
}
2020

21-
func forward<U...>(_ u: U...) -> (U...) {
21+
func forward<U...>(_ u: repeat each U) -> (repeat each U) {
2222
return tuplify(repeat each u)
2323
}
2424

25-
func forwardAndMap<U..., V...>(us u: U..., vs v: V...) -> ([(U, V)]...) {
25+
func forwardAndMap<U..., V...>(us u: repeat each U, vs v: repeat each V) -> (repeat [(each U, each V)]) {
2626
return tuplify(repeat [(each u, each v)])
2727
}
2828

29-
func variadicMap<T..., Result...>(_ t: T..., transform: ((T) -> Result)...) -> (Result...) {
29+
func variadicMap<T..., Result...>(_ t: repeat each T, transform: repeat (each T) -> each Result) -> (repeat each Result) {
3030
return (repeat (each transform)(each t))
3131
}
3232

33-
func coerceExpansion<T...>(_ value: T...) {
34-
func promoteToOptional<Wrapped...>(_: Wrapped?...) {}
33+
func coerceExpansion<T...>(_ value: repeat each T) {
34+
func promoteToOptional<Wrapped...>(_: repeat (each Wrapped)?) {}
3535

3636
promoteToOptional(repeat each value)
3737
}
3838

39-
func localValuePack<T...>(_ t: T...) -> (T..., T...) {
39+
func localValuePack<T...>(_ t: repeat each T) -> (repeat each T, repeat each T) {
4040
let local = repeat each t
41-
let localAnnotated: T... = repeat each t
41+
let localAnnotated: repeat each T = repeat each t
4242

4343
return (repeat each local, repeat each localAnnotated)
4444
}
@@ -51,29 +51,29 @@ protocol P {
5151
func f(_ self: Self) -> Self
5252
}
5353

54-
func outerArchetype<T..., U>(t: T..., u: U) where T: P {
55-
let _: (T.A, U)... = repeat ((each t).value, u)
54+
func outerArchetype<T..., U>(t: repeat each T, u: U) where each T: P {
55+
let _: repeat (each T.A, U) = repeat ((each t).value, u)
5656
}
5757

58-
func sameElement<T..., U>(t: T..., u: U) where T: P, T == U {
59-
let _: T... = repeat (each t).f(u)
58+
func sameElement<T..., U>(t: repeat each T, u: U) where each T: P, each T == U {
59+
let _: repeat each T = repeat (each t).f(u)
6060
}
6161

62-
func forEachEach<C..., U>(c: C..., function: (U) -> Void)
63-
where C: Collection, C.Element == U {
62+
func forEachEach<C..., U>(c: repeat each C, function: (U) -> Void)
63+
where each C: Collection, each C.Element == U {
6464
_ = repeat (each c).forEach(function)
6565
}
6666

67-
func typeReprPacks<T...>(_ t: T...) where T: ExpressibleByIntegerLiteral {
67+
func typeReprPacks<T...>(_ t: repeat each T) where each T: ExpressibleByIntegerLiteral {
6868
_ = repeat Array<each T>()
6969
_ = repeat 1 as each T
7070

7171
_ = Array<each T>() // expected-error {{pack reference 'T' can only appear in pack expansion or generic requirement}}
7272
_ = 1 as each T // expected-error {{pack reference 'T' can only appear in pack expansion or generic requirement}}
7373
}
7474

75-
func sameShapeDiagnostics<T..., U...>(t: T..., u: U...) {
76-
_ = (each t, each u)... // expected-error {{pack expansion requires that 'U' and 'T' have the same shape}}
77-
_ = Array<(each T, each U)>()... // expected-error {{pack expansion requires that 'U' and 'T' have the same shape}}
78-
_ = (Array<each T>(), each u)... // expected-error {{pack expansion requires that 'U' and 'T' have the same shape}}
75+
func sameShapeDiagnostics<T..., U...>(t: repeat each T, u: repeat each U) {
76+
_ = repeat (each t, each u) // expected-error {{pack expansion requires that 'U' and 'T' have the same shape}}
77+
_ = repeat Array<(each T, each U)>() // expected-error {{pack expansion requires that 'U' and 'T' have the same shape}}
78+
_ = repeat (Array<each T>(), each u) // expected-error {{pack expansion requires that 'U' and 'T' have the same shape}}
7979
}

test/Constraints/pack_expansion_types.swift

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
// REQUIRES: asserts
44

5-
func returnTuple1<T...>() -> (T...) { fatalError() }
5+
func returnTuple1<T...>() -> (repeat each T) { fatalError() }
66

7-
func returnTuple2<T...>() -> (Int, T...) { fatalError() }
7+
func returnTuple2<T...>() -> (Int, repeat each T) { fatalError() }
88

9-
func returnTupleLabel1<T...>() -> (x: T...) { fatalError() }
9+
func returnTupleLabel1<T...>() -> (x: repeat each T) { fatalError() }
1010

11-
func returnTupleLabel2<T...>() -> (Int, x: T...) { fatalError() }
11+
func returnTupleLabel2<T...>() -> (Int, x: repeat each T) { fatalError() }
1212

13-
func returnTupleLabel3<T...>() -> (Int, T..., y: Float) { fatalError() }
13+
func returnTupleLabel3<T...>() -> (Int, repeat each T, y: Float) { fatalError() }
1414

15-
func returnTupleLabel4<T...>() -> (Int, x: T..., y: Float) { fatalError() } // expected-note {{in call to function 'returnTupleLabel4()'}}
15+
func returnTupleLabel4<T...>() -> (Int, x: repeat each T, y: Float) { fatalError() } // expected-note {{in call to function 'returnTupleLabel4()'}}
1616

17-
func returnTupleLabel5<T..., U...>() -> (Int, T..., y: U...) { fatalError() }
17+
func returnTupleLabel5<T..., U...>() -> (Int, repeat each T, y: repeat each U) { fatalError() }
1818

19-
func returnTupleLabel6<T..., U...>() -> (Int, x: T..., y: U...) { fatalError() } // expected-note {{in call to function 'returnTupleLabel6()'}}
19+
func returnTupleLabel6<T..., U...>() -> (Int, x: repeat each T, y: repeat each U) { fatalError() } // expected-note {{in call to function 'returnTupleLabel6()'}}
2020

2121
func concreteReturnTupleValid() {
2222
let _: () = returnTuple1()
@@ -66,70 +66,70 @@ func concreteReturnTypeInvalid() {
6666
let _: () = returnTupleLabel5() // expected-error {{type of expression is ambiguous without more context}}
6767
}
6868

69-
func genericReturnTupleValid<T...>(_: T...) {
70-
let _: (T...) = returnTuple1()
71-
let _: (Int, T...) = returnTuple1()
69+
func genericReturnTupleValid<T...>(_: repeat each T) {
70+
let _: (repeat each T) = returnTuple1()
71+
let _: (Int, repeat each T) = returnTuple1()
7272

73-
let _: (Int, T...) = returnTuple2()
74-
let _: (Int, String, T...) = returnTuple2()
73+
let _: (Int, repeat each T) = returnTuple2()
74+
let _: (Int, String, repeat each T) = returnTuple2()
7575

76-
let _: (x: T...) = returnTupleLabel1()
77-
let _: (x: Int, T...) = returnTupleLabel1()
76+
let _: (x: repeat each T) = returnTupleLabel1()
77+
let _: (x: Int, repeat each T) = returnTupleLabel1()
7878

79-
let _: (Int, x: T...) = returnTupleLabel2()
80-
let _: (Int, x: String, T...) = returnTupleLabel2()
79+
let _: (Int, x: repeat each T) = returnTupleLabel2()
80+
let _: (Int, x: String, repeat each T) = returnTupleLabel2()
8181

82-
let _: (Int, T..., y: Float) = returnTupleLabel3()
83-
let _: (Int, String, T..., y: Float) = returnTupleLabel3()
82+
let _: (Int, repeat each T, y: Float) = returnTupleLabel3()
83+
let _: (Int, String, repeat each T, y: Float) = returnTupleLabel3()
8484

85-
let _: (Int, x: T..., y: Float) = returnTupleLabel4()
86-
let _: (Int, x: String, T..., y: Float) = returnTupleLabel4()
85+
let _: (Int, x: repeat each T, y: Float) = returnTupleLabel4()
86+
let _: (Int, x: String, repeat each T, y: Float) = returnTupleLabel4()
8787

88-
let _: (Int, T..., y: T...) = returnTupleLabel5()
89-
let _: (Int, String, T..., y: Float, T...) = returnTupleLabel5()
88+
let _: (Int, repeat each T, y: repeat each T) = returnTupleLabel5()
89+
let _: (Int, String, repeat each T, y: Float, repeat each T) = returnTupleLabel5()
9090

91-
let _: (Int, x: T..., y: T...) = returnTupleLabel6()
92-
let _: (Int, x: String, T..., y: Float, T...) = returnTupleLabel6()
91+
let _: (Int, x: repeat each T, y: repeat each T) = returnTupleLabel6()
92+
let _: (Int, x: String, repeat each T, y: Float, repeat each T) = returnTupleLabel6()
9393
}
9494

95-
func genericReturnTupleInvalid<T...>(_: T...) {
96-
let _: (x: T...) = returnTuple1() // expected-error {{type of expression is ambiguous without more context}}
97-
let _: (x: Int, T...) = returnTuple1() // expected-error {{type of expression is ambiguous without more context}}
95+
func genericReturnTupleInvalid<T...>(_: repeat each T) {
96+
let _: (x: repeat each T) = returnTuple1() // expected-error {{type of expression is ambiguous without more context}}
97+
let _: (x: Int, repeat each T) = returnTuple1() // expected-error {{type of expression is ambiguous without more context}}
9898

99-
let _: (Int, x: T...) = returnTuple2() // expected-error {{type of expression is ambiguous without more context}}
100-
let _: (Int, x: String, T...) = returnTuple2() // expected-error {{type of expression is ambiguous without more context}}
99+
let _: (Int, x: repeat each T) = returnTuple2() // expected-error {{type of expression is ambiguous without more context}}
100+
let _: (Int, x: String, repeat each T) = returnTuple2() // expected-error {{type of expression is ambiguous without more context}}
101101

102-
let _: (y: T...) = returnTupleLabel1() // expected-error {{type of expression is ambiguous without more context}}
103-
let _: (y: Int, T...) = returnTupleLabel1() // expected-error {{type of expression is ambiguous without more context}}
102+
let _: (y: repeat each T) = returnTupleLabel1() // expected-error {{type of expression is ambiguous without more context}}
103+
let _: (y: Int, repeat each T) = returnTupleLabel1() // expected-error {{type of expression is ambiguous without more context}}
104104

105-
let _: (x: T...) = returnTupleLabel2() // expected-error {{type of expression is ambiguous without more context}}
106-
let _: (Int, y: String, T...) = returnTupleLabel2() // expected-error {{type of expression is ambiguous without more context}}
105+
let _: (x: repeat each T) = returnTupleLabel2() // expected-error {{type of expression is ambiguous without more context}}
106+
let _: (Int, y: String, repeat each T) = returnTupleLabel2() // expected-error {{type of expression is ambiguous without more context}}
107107

108-
let _: (T..., y: Float) = returnTupleLabel3() // expected-error {{type of expression is ambiguous without more context}}
108+
let _: (repeat each T, y: Float) = returnTupleLabel3() // expected-error {{type of expression is ambiguous without more context}}
109109

110-
let _: (Int, String, T..., x: Float) = returnTupleLabel3() // expected-error {{type of expression is ambiguous without more context}}
110+
let _: (Int, String, repeat each T, x: Float) = returnTupleLabel3() // expected-error {{type of expression is ambiguous without more context}}
111111

112-
let _: (T..., y: Float) = returnTupleLabel4() // expected-error {{'(Int, x: T..., y: Float)' is not convertible to '(T..., y: Float)', tuples have a different number of elements}}
112+
let _: (repeat each T, y: Float) = returnTupleLabel4() // expected-error {{'(Int, x: T..., y: Float)' is not convertible to '(T..., y: Float)', tuples have a different number of elements}}
113113
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
114114

115-
let _: (Int, x: String, y: T...) = returnTupleLabel4() // expected-error {{cannot convert value of type '(Int, x: String, y: Float)' to specified type '(Int, x: String, y: T...)'}}
115+
let _: (Int, x: String, y: repeat each T) = returnTupleLabel4() // expected-error {{cannot convert value of type '(Int, x: String, y: Float)' to specified type '(Int, x: String, y: T...)'}}
116116

117-
let _: (Int, T..., x: T...) = returnTupleLabel5() // expected-error {{type of expression is ambiguous without more context}}
117+
let _: (Int, repeat each T, x: repeat each T) = returnTupleLabel5() // expected-error {{type of expression is ambiguous without more context}}
118118

119-
let _: (T..., y: Float, T...) = returnTupleLabel5() // expected-error {{type of expression is ambiguous without more context}}
119+
let _: (repeat each T, y: Float, repeat each T) = returnTupleLabel5() // expected-error {{type of expression is ambiguous without more context}}
120120

121-
let _: (T..., y: Int) = returnTupleLabel6() // expected-error {{'(Int, x: T..., y: U...)' is not convertible to '(T..., y: Int)', tuples have a different number of elements}}
121+
let _: (repeat each T, y: Int) = returnTupleLabel6() // expected-error {{'(Int, x: T..., y: U...)' is not convertible to '(T..., y: Int)', tuples have a different number of elements}}
122122
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
123123
// expected-error@-2 {{generic parameter 'U' could not be inferred}}
124124
}
125125

126-
func returnFunction1<T...>() -> (T...) -> () {}
126+
func returnFunction1<T...>() -> (repeat each T) -> () {}
127127

128-
func returnFunction2<T...>() -> (Int, T...) -> () {} // expected-note {{in call to function 'returnFunction2()'}}
128+
func returnFunction2<T...>() -> (Int, repeat each T) -> () {} // expected-note {{in call to function 'returnFunction2()'}}
129129

130-
func returnFunction3<T...>() -> (T..., Float) -> () {} // expected-note {{in call to function 'returnFunction3()'}}
130+
func returnFunction3<T...>() -> (repeat each T, Float) -> () {} // expected-note {{in call to function 'returnFunction3()'}}
131131

132-
func returnFunction4<T...>() -> (Int, T..., Float) -> () {} // expected-note 2{{in call to function 'returnFunction4()'}}
132+
func returnFunction4<T...>() -> (Int, repeat each T, Float) -> () {} // expected-note 2{{in call to function 'returnFunction4()'}}
133133

134134
func concreteReturnFunctionValid() {
135135
let _: () -> () = returnFunction1()
@@ -171,11 +171,11 @@ func concreteReturnFunctionInvalid() {
171171
let _: (Float, Int) -> () = returnFunction4() // expected-error {{cannot convert value of type '(Int, Float) -> ()' to specified type '(Float, Int) -> ()'}}
172172
}
173173

174-
func patternInstantiationTupleTest1<T...>() -> (Array<T>...) {} // expected-note {{in call to function 'patternInstantiationTupleTest1()'}}
175-
func patternInstantiationTupleTest2<T..., U...>() -> (Dictionary<T, U>...) {}
174+
func patternInstantiationTupleTest1<T...>() -> (repeat Array<each T>) {} // expected-note {{in call to function 'patternInstantiationTupleTest1()'}}
175+
func patternInstantiationTupleTest2<T..., U...>() -> (repeat Dictionary<each T, each U>) {}
176176

177-
func patternInstantiationFunctionTest1<T...>() -> (Array<T>...) -> () {}
178-
func patternInstantiationFunctionTest2<T..., U...>() -> (Dictionary<T, U>...) -> () {}
177+
func patternInstantiationFunctionTest1<T...>() -> (repeat Array<each T>) -> () {}
178+
func patternInstantiationFunctionTest2<T..., U...>() -> (repeat Dictionary<each T, each U>) -> () {}
179179

180180
func patternInstantiationConcreteValid() {
181181
let _: () = patternInstantiationTupleTest1()
@@ -204,31 +204,31 @@ func patternInstantiationConcreteInvalid() {
204204
let _: (Array<Int>, Set<String>) = patternInstantiationTupleTest1() // expected-error {{type of expression is ambiguous without more context}}
205205
}
206206

207-
func patternInstantiationGenericValid<T..., U...>(t: T..., u: U...) where ((T, U)...): Any, T: Hashable {
208-
let _: (Array<T>...) = patternInstantiationTupleTest1()
209-
let _: (Array<T>..., Array<String>) = patternInstantiationTupleTest1()
210-
let _: (Array<String>, Array<T>...) = patternInstantiationTupleTest1()
211-
let _: (Array<Int>, Array<T>..., Array<Float>) = patternInstantiationTupleTest1()
212-
213-
let _: (Dictionary<T, U>...) = patternInstantiationTupleTest2()
214-
let _: (Dictionary<T, U>..., Dictionary<Float, Bool>) = patternInstantiationTupleTest2()
215-
let _: (Dictionary<Int, String>, Dictionary<T, U>...) = patternInstantiationTupleTest2()
216-
let _: (Dictionary<Int, String>, Dictionary<T, U>..., Dictionary<Double, Character>) = patternInstantiationTupleTest2()
217-
218-
let _: (Array<T>...) -> () = patternInstantiationFunctionTest1()
219-
let _: (Array<T>..., Array<String>) -> () = patternInstantiationFunctionTest1()
220-
let _: (Array<String>, Array<T>...) -> () = patternInstantiationFunctionTest1()
221-
let _: (Array<Int>, Array<T>..., Array<Float>) -> () = patternInstantiationFunctionTest1()
222-
223-
let _: (Dictionary<T, U>...) -> () = patternInstantiationFunctionTest2()
224-
let _: (Dictionary<T, U>..., Dictionary<Float, Bool>) -> () = patternInstantiationFunctionTest2()
225-
let _: (Dictionary<Int, String>, Dictionary<T, U>...) -> () = patternInstantiationFunctionTest2()
226-
let _: (Dictionary<Int, String>, Dictionary<T, U>..., Dictionary<Double, Character>) -> () = patternInstantiationFunctionTest2()
207+
func patternInstantiationGenericValid<T..., U...>(t: repeat each T, u: repeat each U) where (repeat (each T, each U)): Any, T: Hashable {
208+
let _: (repeat Array<each T>) = patternInstantiationTupleTest1()
209+
let _: (repeat Array<each T>, Array<String>) = patternInstantiationTupleTest1()
210+
let _: (Array<String>, repeat Array<each T>) = patternInstantiationTupleTest1()
211+
let _: (Array<Int>, repeat Array<each T>, Array<Float>) = patternInstantiationTupleTest1()
212+
213+
let _: (repeat Dictionary<each T, each U>) = patternInstantiationTupleTest2()
214+
let _: (repeat Dictionary<each T, each U>, Dictionary<Float, Bool>) = patternInstantiationTupleTest2()
215+
let _: (Dictionary<Int, String>, repeat Dictionary<each T, each U>) = patternInstantiationTupleTest2()
216+
let _: (Dictionary<Int, String>, repeat Dictionary<each T, each U>, Dictionary<Double, Character>) = patternInstantiationTupleTest2()
217+
218+
let _: (repeat Array<each T>) -> () = patternInstantiationFunctionTest1()
219+
let _: (repeat Array<each T>, Array<String>) -> () = patternInstantiationFunctionTest1()
220+
let _: (Array<String>, repeat Array<each T>) -> () = patternInstantiationFunctionTest1()
221+
let _: (Array<Int>, repeat Array<each T>, Array<Float>) -> () = patternInstantiationFunctionTest1()
222+
223+
let _: (repeat Dictionary<each T, each U>) -> () = patternInstantiationFunctionTest2()
224+
let _: (repeat Dictionary<each T, each U>, Dictionary<Float, Bool>) -> () = patternInstantiationFunctionTest2()
225+
let _: (Dictionary<Int, String>, repeat Dictionary<each T, each U>) -> () = patternInstantiationFunctionTest2()
226+
let _: (Dictionary<Int, String>, repeat Dictionary<each T, each U>, Dictionary<Double, Character>) -> () = patternInstantiationFunctionTest2()
227227
}
228228

229-
func patternInstantiationGenericInvalid<T...>(t: T...) where T: Hashable {
230-
let _: (Set<T>...) = patternInstantiationTupleTest1() // expected-error {{cannot convert value of type '(Array<T>...)' to specified type '(Set<T>...)}}
229+
func patternInstantiationGenericInvalid<T...>(t: repeat each T) where T: Hashable {
230+
let _: (repeat Set<each T>) = patternInstantiationTupleTest1() // expected-error {{cannot convert value of type '(Array<T>...)' to specified type '(Set<T>...)}}
231231
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
232232

233-
let _: (Array<T>..., Set<String>) = patternInstantiationTupleTest1() // expected-error {{type of expression is ambiguous without more context}}
233+
let _: (repeat Array<each T>, Set<String>) = patternInstantiationTupleTest1() // expected-error {{type of expression is ambiguous without more context}}
234234
}

test/Constraints/tuple.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ var values = getIntFloat()
7474
func wantFloat(_: Float) {}
7575
wantFloat(values.float)
7676

77-
var e : (x: Int..., y: Int) // expected-error{{variadic expansion 'Int' must contain at least one variadic generic parameter}}
77+
var e : (x: Int..., y: Int) // expected-error{{variadic parameter cannot appear outside of a function parameter list}}
7878

7979
typealias Interval = (a:Int, b:Int)
8080
func takeInterval(_ x: Interval) {}

0 commit comments

Comments
 (0)