Skip to content

Commit 5a2406b

Browse files
committed
Move some closure related testcases out to Constraints/closures.swift,
since Constraints/diagnostics.swift is already so huge. NFC.
1 parent 84d27f8 commit 5a2406b

File tree

2 files changed

+77
-74
lines changed

2 files changed

+77
-74
lines changed

test/Constraints/closures.swift

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,79 @@ func r21675896(file : String) {
231231
}
232232

233233

234+
235+
236+
// <rdar://problem/19870975> Incorrect diagnostic for failed member lookups within closures passed as arguments ("(_) -> _")
237+
func ident<T>(_ t: T) -> T {}
238+
var c = ident({1.DOESNT_EXIST}) // error: expected-error {{value of type 'Int' has no member 'DOESNT_EXIST'}}
239+
240+
// <rdar://problem/20712541> QoI: Int/UInt mismatch produces useless error inside a block
241+
var afterMessageCount : Int? = nil
242+
243+
func uintFunc() -> UInt {}
244+
func takeVoidVoidFn(_ a : () -> ()) {}
245+
takeVoidVoidFn { () -> Void in
246+
afterMessageCount = uintFunc() // expected-error {{cannot assign value of type 'UInt' to type 'Int?'}}
247+
}
248+
249+
// <rdar://problem/19997471> Swift: Incorrect compile error when calling a function inside a closure
250+
func f19997471(_ x: String) {}
251+
func f19997471(_ x: Int) {}
252+
253+
func someGeneric19997471<T>(_ x: T) {
254+
takeVoidVoidFn {
255+
f19997471(x) // expected-error {{cannot invoke 'f19997471' with an argument list of type '(T)'}}
256+
// expected-note @-1 {{overloads for 'f19997471' exist with these partially matching parameter lists: (String), (Int)}}
257+
}
258+
}
259+
260+
// <rdar://problem/20371273> Type errors inside anonymous functions don't provide enough information
261+
func f20371273() {
262+
let x: [Int] = [1, 2, 3, 4]
263+
let y: UInt = 4
264+
x.filter { $0 == y } // expected-error {{binary operator '==' cannot be applied to operands of type 'Int' and 'UInt'}}
265+
// expected-note @-1 {{overloads for '==' exist with these partially matching parameter lists: (UInt, UInt), (Int, Int)}}
266+
}
267+
268+
269+
270+
271+
// <rdar://problem/20921068> Swift fails to compile: [0].map() { _ in let r = (1,2).0; return r }
272+
[0].map { // expected-error {{unable to infer closure return type in current context}}
273+
_ in
274+
let r = (1,2).0
275+
return r
276+
}
277+
278+
279+
// <rdar://problem/21078316> Less than useful error message when using map on optional dictionary type
280+
func rdar21078316() {
281+
var foo : [String : String]?
282+
var bar : [(String, String)]?
283+
bar = foo.map { ($0, $1) } // expected-error {{contextual closure type '([String : String]) -> [(String, String)]' expects 1 argument, but 2 were used in closure body}}
284+
}
285+
286+
287+
// <rdar://problem/20978044> QoI: Poor diagnostic when using an incorrect tuple element in a closure
288+
var numbers = [1, 2, 3]
289+
zip(numbers, numbers).filter { $0.2 > 1 } // expected-error {{value of tuple type '(Int, Int)' has no member '2'}}
290+
291+
292+
293+
// <rdar://problem/20868864> QoI: Cannot invoke 'function' with an argument list of type 'type'
294+
func foo20868864(_ callback: ([String]) -> ()) { }
295+
func rdar20868864(_ s: String) {
296+
var s = s
297+
foo20868864 { (strings: [String]) in
298+
s = strings // expected-error {{cannot assign value of type '[String]' to type 'String'}}
299+
}
300+
}
301+
302+
// <rdar://problem/22058555> crash in cs diags in withCString
303+
func r22058555() {
304+
var firstChar: UInt8 = 0
305+
"abc".withCString { chars in
306+
firstChar = chars[0] // expected-error {{cannot assign value of type 'Int8' to type 'UInt8'}}
307+
}
308+
}
309+

test/Constraints/diagnostics.swift

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -428,73 +428,6 @@ CurriedClass.m2(12) // expected-error {{use of instance member 'm2' on type 'Cu
428428

429429

430430

431-
432-
// <rdar://problem/19870975> Incorrect diagnostic for failed member lookups within closures passed as arguments ("(_) -> _")
433-
func ident<T>(_ t: T) -> T {}
434-
var c = ident({1.DOESNT_EXIST}) // error: expected-error {{value of type 'Int' has no member 'DOESNT_EXIST'}}
435-
436-
// <rdar://problem/20712541> QoI: Int/UInt mismatch produces useless error inside a block
437-
var afterMessageCount : Int? = nil
438-
439-
func uintFunc() -> UInt {}
440-
func takeVoidVoidFn(_ a : () -> ()) {}
441-
takeVoidVoidFn { () -> Void in
442-
afterMessageCount = uintFunc() // expected-error {{cannot assign value of type 'UInt' to type 'Int?'}}
443-
}
444-
445-
// <rdar://problem/19997471> Swift: Incorrect compile error when calling a function inside a closure
446-
func f19997471(_ x: String) {}
447-
func f19997471(_ x: Int) {}
448-
449-
func someGeneric19997471<T>(_ x: T) {
450-
takeVoidVoidFn {
451-
f19997471(x) // expected-error {{cannot invoke 'f19997471' with an argument list of type '(T)'}}
452-
// expected-note @-1 {{overloads for 'f19997471' exist with these partially matching parameter lists: (String), (Int)}}
453-
}
454-
}
455-
456-
// <rdar://problem/20371273> Type errors inside anonymous functions don't provide enough information
457-
func f20371273() {
458-
let x: [Int] = [1, 2, 3, 4]
459-
let y: UInt = 4
460-
x.filter { $0 == y } // expected-error {{binary operator '==' cannot be applied to operands of type 'Int' and 'UInt'}}
461-
// expected-note @-1 {{overloads for '==' exist with these partially matching parameter lists: (UInt, UInt), (Int, Int)}}
462-
}
463-
464-
465-
466-
467-
// <rdar://problem/20921068> Swift fails to compile: [0].map() { _ in let r = (1,2).0; return r }
468-
[0].map { // expected-error {{unable to infer closure return type in current context}}
469-
_ in
470-
let r = (1,2).0
471-
return r
472-
}
473-
474-
475-
// <rdar://problem/21078316> Less than useful error message when using map on optional dictionary type
476-
func rdar21078316() {
477-
var foo : [String : String]?
478-
var bar : [(String, String)]?
479-
bar = foo.map { ($0, $1) } // expected-error {{contextual closure type '([String : String]) -> [(String, String)]' expects 1 argument, but 2 were used in closure body}}
480-
}
481-
482-
483-
// <rdar://problem/20978044> QoI: Poor diagnostic when using an incorrect tuple element in a closure
484-
var numbers = [1, 2, 3]
485-
zip(numbers, numbers).filter { $0.2 > 1 } // expected-error {{value of tuple type '(Int, Int)' has no member '2'}}
486-
487-
488-
489-
// <rdar://problem/20868864> QoI: Cannot invoke 'function' with an argument list of type 'type'
490-
func foo20868864(_ callback: ([String]) -> ()) { }
491-
func rdar20868864(_ s: String) {
492-
var s = s
493-
foo20868864 { (strings: [String]) in
494-
s = strings // expected-error {{cannot assign value of type '[String]' to type 'String'}}
495-
}
496-
}
497-
498431
// <rdar://problem/20491794> Error message does not tell me what the problem is
499432
enum Color {
500433
case Red // expected-note 2 {{did you mean 'Red'?}}
@@ -709,13 +642,7 @@ func segfault23433271(_ a : UnsafeMutableRawPointer) {
709642
f23433271(a[0]) // expected-error {{type 'UnsafeMutableRawPointer' has no subscript members}}
710643
}
711644

712-
// <rdar://problem/22058555> crash in cs diags in withCString
713-
func r22058555() {
714-
var firstChar: UInt8 = 0
715-
"abc".withCString { chars in
716-
firstChar = chars[0] // expected-error {{cannot assign value of type 'Int8' to type 'UInt8'}}
717-
}
718-
}
645+
719646

720647
// <rdar://problem/23272739> Poor diagnostic due to contextual constraint
721648
func r23272739(_ contentType: String) {

0 commit comments

Comments
 (0)