Skip to content

Commit 5401ed3

Browse files
[tests] Add regression test cases for SR-13239
1 parent c02f30f commit 5401ed3

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

test/expr/closure/closures.swift

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,3 +606,66 @@ func testSR14678_Optional() -> (Int, Int)? {
606606
(print("hello"), 0)
607607
}
608608
}
609+
610+
// SR-13239
611+
func callit<T>(_ f: () -> T) -> T {
612+
f()
613+
}
614+
615+
func callitArgs<T>(_ : Int, _ f: () -> T) -> T {
616+
f()
617+
}
618+
619+
func callitArgsFn<T>(_ : Int, _ f: () -> () -> T) -> T {
620+
f()()
621+
}
622+
623+
func callitGenericArg<T>(_ a: T, _ f: () -> T) -> T {
624+
f()
625+
}
626+
627+
func callitTuple<T>(_ : Int, _ f: () -> (T, Int)) -> T {
628+
f().0
629+
}
630+
631+
func testSR13239_Tuple() -> Int {
632+
// expected-error@+1{{conflicting inferred types from call result and closure argument to generic parameter 'T' ('()' vs. 'Int')}}
633+
callitTuple(1) {
634+
(print("hello"), 0)
635+
}
636+
}
637+
638+
func testSR13239() -> Int {
639+
// expected-error@+1{{conflicting inferred types from call result and closure argument to generic parameter 'T' ('()' vs. 'Int')}}
640+
callit {
641+
print("hello")
642+
}
643+
}
644+
645+
func testSR13239_Args() -> Int {
646+
// expected-error@+1{{conflicting inferred types from call result and closure argument to generic parameter 'T' ('()' vs. 'Int')}}
647+
callitArgs(1) {
648+
print("hello")
649+
}
650+
}
651+
652+
func testSR13239_ArgsFn() -> Int {
653+
// expected-error@+1{{conflicting inferred types from call result and closure argument to generic parameter 'T' ('()' vs. 'Int')}}
654+
callitArgsFn(1) {
655+
{ print("hello") }
656+
}
657+
}
658+
659+
func testSR13239MultiExpr() -> Int {
660+
callit {
661+
print("hello")
662+
return print("hello") // expected-error {{cannot convert return expression of type '()' to return type 'Int'}}
663+
}
664+
}
665+
666+
func testSR13239_GenericArg() -> Int {
667+
// Generic argument is inferred as Int from first argument literal, so no conflict in this case.
668+
callitGenericArg(1) {
669+
print("hello") // expected-error {{cannot convert value of type '()' to closure result type 'Int'}}
670+
}
671+
}

0 commit comments

Comments
 (0)