|
1 |
| -// RUN: %target-typecheck-verify-swift -swift-version 4 |
| 1 | +// RUN: %target-typecheck-verify-swift |
2 | 2 |
|
3 | 3 | func myMap<T1, T2>(_ array: [T1], _ fn: (T1) -> T2) -> [T2] {}
|
4 | 4 |
|
@@ -539,6 +539,15 @@ _ = ["hi"].compactMap { $0.isEmpty ? nil : $0 }
|
539 | 539 | // rdar://problem/32432145 - compiler should emit fixit to remove "_ in" in closures if 0 parameters is expected
|
540 | 540 |
|
541 | 541 | func r32432145(_ a: () -> ()) {}
|
| 542 | + |
| 543 | +r32432145 { _ in let _ = 42 } |
| 544 | +// expected-error@-1 {{contextual closure type '() -> ()' expects 0 arguments, but 1 was used in closure body}} {{13-17=}} |
| 545 | + |
| 546 | +r32432145 { _ in |
| 547 | + // expected-error@-1 {{contextual closure type '() -> ()' expects 0 arguments, but 1 was used in closure body}} {{13-17=}} |
| 548 | + print("answer is 42") |
| 549 | +} |
| 550 | + |
542 | 551 | r32432145 { _,_ in
|
543 | 552 | // expected-error@-1 {{contextual closure type '() -> ()' expects 0 arguments, but 2 were used in closure body}} {{13-19=}}
|
544 | 553 | print("answer is 42")
|
@@ -733,3 +742,10 @@ func takesTwoInOut(_: (Int, inout Int) -> ()) {}
|
733 | 742 |
|
734 | 743 | takesTwo { _ in } // expected-error {{contextual closure type '(Int, Int) -> ()' expects 2 arguments, but 1 was used in closure body}}
|
735 | 744 | takesTwoInOut { _ in } // expected-error {{contextual closure type '(Int, inout Int) -> ()' expects 2 arguments, but 1 was used in closure body}}
|
| 745 | + |
| 746 | +// <rdar://problem/20371273> Type errors inside anonymous functions don't provide enough information |
| 747 | +func f20371273() { |
| 748 | + let x: [Int] = [1, 2, 3, 4] |
| 749 | + let y: UInt = 4 |
| 750 | + _ = x.filter { ($0 + y) > 42 } // expected-error {{'+' is unavailable}} |
| 751 | +} |
0 commit comments