Skip to content

Commit 766c087

Browse files
committed
[TypeChecker] NFC: Add test-cases for SR-12291
1 parent 5af04d3 commit 766c087

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/Constraints/closures.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,3 +1004,15 @@ func rdar52204414() {
10041004
let _ = { () -> Void in return 42 }
10051005
// expected-error@-1 {{declared closure result 'Int' is incompatible with contextual type 'Void'}}
10061006
}
1007+
1008+
// SR-12291 - trailing closure is used as an argument to the last (positionally) parameter
1009+
func overloaded_with_default(a: () -> Int, b: Int = 0, c: Int = 0) {}
1010+
func overloaded_with_default(b: Int = 0, c: Int = 0, a: () -> Int) {}
1011+
1012+
overloaded_with_default { 0 } // Ok (could be ambiguous if trailing was allowed to match `a:` in first overload)
1013+
1014+
func overloaded_with_default_and_autoclosure<T>(_ a: @autoclosure () -> T, b: Int = 0) {}
1015+
func overloaded_with_default_and_autoclosure<T>(b: Int = 0, c: @escaping () -> T?) {}
1016+
1017+
overloaded_with_default_and_autoclosure { 42 } // Ok
1018+
overloaded_with_default_and_autoclosure(42) // Ok

0 commit comments

Comments
 (0)