1
1
// RUN: %target-typecheck-verify-swift
2
2
3
3
func returnTuple1< each T > ( ) -> ( repeat each T ) { fatalError ( ) }
4
- // expected-note@-1 3 {{in call to function 'returnTuple1()'}}
4
+ // expected-note@-1 {{in call to function 'returnTuple1()'}}
5
5
6
6
func returnTuple2< each T > ( ) -> ( Int , repeat each T ) { fatalError ( ) }
7
- // expected-note@-1 3 {{in call to function 'returnTuple2()'}}
7
+ // expected-note@-1 2 {{in call to function 'returnTuple2()'}}
8
8
9
9
func returnTupleLabel1< each T > ( ) -> ( x: repeat each T ) { fatalError ( ) }
10
10
// expected-error@-1 {{cannot use label with pack expansion tuple element}}
@@ -26,16 +26,10 @@ func returnTupleLabel6<each T, each U>() -> (Int, x: repeat each T, y: repeat ea
26
26
27
27
func concreteReturnTupleValid( ) {
28
28
let _: ( ) = returnTuple1 ( )
29
- // FIXME: consider propagating 'Int' through the conversion constraint
30
- // as a binding for the parameter pack expanded in the tuple return type.
31
29
let _: Int = returnTuple1 ( )
32
- // expected-error@-1 {{generic parameter 'each T' could not be inferred}}
33
- // expected-error@-2 {{cannot convert value of type '(repeat each T)' to specified type 'Int'}}
34
30
let _: ( Int , String ) = returnTuple1 ( )
35
31
36
32
let _: Int = returnTuple2 ( )
37
- // expected-error@-1 {{generic parameter 'each T' could not be inferred}}
38
- // expected-error@-2 {{cannot convert value of type '(Int, repeat each T)' to specified type 'Int'}}
39
33
let _: ( Int , String ) = returnTuple2 ( )
40
34
let _: ( Int , String , Float ) = returnTuple2 ( )
41
35
@@ -72,8 +66,6 @@ func concreteReturnTupleValid() {
72
66
73
67
func concreteReturnTypeInvalid( ) {
74
68
let _: Int = returnTuple1 ( )
75
- // expected-error@-1 {{cannot convert value of type '(repeat each T)' to specified type 'Int'}}
76
- // expected-error@-2 {{generic parameter 'each T' could not be inferred}}
77
69
78
70
let _: ( ) = returnTuple2 ( )
79
71
// expected-error@-1 {{'(Int, repeat each T)' is not convertible to '()', tuples have a different number of elements}}
@@ -218,28 +210,20 @@ func concreteReturnFunctionInvalid() {
218
210
}
219
211
220
212
func patternInstantiationTupleTest1< each T > ( ) -> ( repeat Array < each T > ) { }
221
- // expected-note@-1 3 {{in call to function 'patternInstantiationTupleTest1()'}}
213
+ // expected-note@-1 2 {{in call to function 'patternInstantiationTupleTest1()'}}
222
214
func patternInstantiationTupleTest2< each T , each U > ( ) -> ( repeat Dictionary < each T , each U > ) { }
223
- // expected-note@-1 {{in call to function 'patternInstantiationTupleTest2()'}}
224
215
225
216
func patternInstantiationFunctionTest1< each T > ( ) -> ( repeat Array < each T > ) -> ( ) { }
226
217
func patternInstantiationFunctionTest2< each T , each U > ( ) -> ( repeat Dictionary < each T , each U > ) -> ( ) { }
227
218
228
219
func patternInstantiationConcreteValid( ) {
229
220
let _: ( ) = patternInstantiationTupleTest1 ( )
230
- // FIXME
231
221
let _: Array < Int > = patternInstantiationTupleTest1 ( )
232
- // expected-error@-1 {{generic parameter 'each T' could not be inferred}}
233
- // expected-error@-2 {{cannot convert value of type '(repeat Array<each T>)' to specified type 'Array<Int>'}}
234
222
let _: ( Array < Int > , Array < String > ) = patternInstantiationTupleTest1 ( )
235
223
let _: ( Array < Int > , Array < String > , Array < Float > ) = patternInstantiationTupleTest1 ( )
236
224
237
225
let _: ( ) = patternInstantiationTupleTest2 ( )
238
- // FIXME
239
226
let _: Dictionary < Int , String > = patternInstantiationTupleTest2 ( )
240
- // expected-error@-1 {{generic parameter 'each T' could not be inferred}}
241
- // expected-error@-2 {{generic parameter 'each U' could not be inferred}}
242
- // expected-error@-3 {{cannot convert value of type '(repeat Dictionary<each T, each U>)' to specified type 'Dictionary<Int, String>'}}
243
227
let _: ( Dictionary < Int , String > , Dictionary < Float , Bool > ) = patternInstantiationTupleTest2 ( )
244
228
let _: ( Dictionary < Int , String > , Dictionary < Float , Bool > , Dictionary < Double , Character > ) = patternInstantiationTupleTest2 ( )
245
229
@@ -291,3 +275,26 @@ func patternInstantiationGenericInvalid<each T: Hashable>(t: repeat each T) {
291
275
292
276
let _: ( repeat Array < each T > , Set < String > ) = patternInstantiationTupleTest1 ( ) // expected-error {{type of expression is ambiguous without more context}}
293
277
}
278
+
279
+ // rdar://107996926 - Vanishing metatype of tuple not supported
280
+ func test_one_element_tuple_vs_non_tuple_matching( ) {
281
+ struct S {
282
+ func test< each T > ( _: ( repeat each T ) . Type) -> ( repeat each T ) { fatalError ( ) }
283
+ func testVanishing< each T > ( _: ( Int , repeat each T ) ) { }
284
+ }
285
+
286
+ let _ = S ( ) . test ( Int . self) // Ok
287
+ let _: Int = S ( ) . test ( Int . self) // Ok
288
+ let _ = S ( ) . test ( ( Int, String) . self) // Ok
289
+ let _ = S ( ) . testVanishing ( 42 ) // Ok
290
+
291
+ do {
292
+ struct V < T> { }
293
+
294
+ func test< each T > ( _: V < ( repeat each T ) > ? ) { }
295
+ func test< each T > ( _: V < ( repeat each T ) > . Type ) { }
296
+
297
+ test ( V < Int > ( ) ) // Ok
298
+ test ( V< Int> . self ) // Ok
299
+ }
300
+ }
0 commit comments