Skip to content

Commit 0653328

Browse files
committed
Sema: Tests for matching function types containing pack expansion types
1 parent 5a9e43e commit 0653328

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/Constraints/pack_expansion_types.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,48 @@ func genericReturnTupleInvalid<@_typeSequence T>(_: T...) {
117117
// expected-error@-1 {{'(Int, T..., y: Float, T...)' is not convertible to '(T..., y: Float, T...)', tuples have a different number of elements}}
118118

119119
let _: (T..., y: Int) = returnTupleLabel6() // expected-error {{cannot convert value of type '(Int, y: Int)' to specified type '(T..., y: Int)'}}
120+
}
121+
122+
func returnFunction1<@_typeSequence T>() -> (T...) -> () {}
123+
124+
func returnFunction2<@_typeSequence T>() -> (Int, T...) -> () {} // expected-note {{in call to function 'returnFunction2()'}}
125+
126+
func returnFunction3<@_typeSequence T>() -> (T..., Float) -> () {} // expected-note {{in call to function 'returnFunction3()'}}
127+
128+
func returnFunction4<@_typeSequence T>() -> (Int, T..., Float) -> () {} // expected-note 2{{in call to function 'returnFunction4()'}}
129+
130+
func concreteReturnFunctionValid() {
131+
let _: () -> () = returnFunction1()
132+
let _: (Int) -> () = returnFunction1()
133+
let _: (String, Double) -> () = returnFunction1()
134+
135+
let _: (Int) -> () = returnFunction2()
136+
let _: (Int, Int) -> () = returnFunction2()
137+
let _: (Int, String, Double) -> () = returnFunction2()
138+
139+
let _: (Float) -> () = returnFunction3()
140+
let _: (Int, Float) -> () = returnFunction3()
141+
let _: (String, Double, Float) -> () = returnFunction3()
142+
143+
let _: (Int, Float) -> () = returnFunction4()
144+
let _: (Int, Int, Float) -> () = returnFunction4()
145+
let _: (Int, String, Double, Float) -> () = returnFunction4()
146+
}
147+
148+
func concreteReturnFunctionInvalid() {
149+
let _: () -> () = returnFunction2() // expected-error {{cannot convert value of type '(Int, T...) -> ()' to specified type '() -> ()'}}
150+
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
151+
let _: (String) -> () = returnFunction2() // expected-error {{cannot convert value of type '(Int) -> ()' to specified type '(String) -> ()'}}
152+
let _: (String, Int) -> () = returnFunction2() // expected-error {{cannot convert value of type '(Int, Int) -> ()' to specified type '(String, Int) -> ()'}}
153+
154+
let _: () -> () = returnFunction3() // expected-error {{cannot convert value of type '(T..., Float) -> ()' to specified type '() -> ()'}}
155+
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
156+
let _: (Float, Int) -> () = returnFunction3() // expected-error {{cannot convert value of type '(Float, Float) -> ()' to specified type '(Float, Int) -> ()'}}
157+
let _: (Float, Double, String) -> () = returnFunction3() // expected-error {{cannot convert value of type '(Float, Double, Float) -> ()' to specified type '(Float, Double, String) -> ()'}}
158+
159+
let _: () -> () = returnFunction4() // expected-error {{cannot convert value of type '(Int, T..., Float) -> ()' to specified type '() -> ()'}}
160+
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
161+
let _: (Int) -> () = returnFunction4() // expected-error {{cannot convert value of type '(Int, T..., Float) -> ()' to specified type '(Int) -> ()'}}
162+
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
163+
let _: (Float, Int) -> () = returnFunction4() // expected-error {{cannot convert value of type '(Int, Float) -> ()' to specified type '(Float, Int) -> ()'}}
120164
}

0 commit comments

Comments
 (0)