@@ -488,3 +488,39 @@ func rdar92521618() {
488488 if let _ = { foo { } } ( ) { }
489489 guard let _ = { foo { } } ( ) else { return }
490490}
491+
492+ // Argument matching never binds trailing closure arguments to
493+ // defaulted/variadic parameters of non-function type.
494+ do {
495+ // Trailing closure not considered fulfilled by 'arg'.
496+ // Note: Used to crash.
497+ do {
498+ func variadic( arg: Int ... ) { } // expected-note@:10 {{'variadic(arg:)' declared here}}{{none}}
499+ func defaulted( arg: Int = 0 ) { }
500+
501+ let _ = variadic { return ( ) }
502+ // expected-error@-1:22 {{trailing closure passed to parameter of type 'Int' that does not accept a closure}}{{none}}
503+ let _ = defaulted { return ( ) }
504+ // expected-error@-1:23 {{extra trailing closure passed in call}}{{none}}
505+ }
506+ // Trailing closure considered fulfilled by 'x' instead of 'arg'.
507+ do {
508+ func variadic( arg: Int ... , x: String ) { } // expected-note@:10 {{'variadic(arg:x:)' declared here}}{{none}}
509+ func defaulted( arg: Int = 0 , x: String ) { } // expected-note@:10 {{'defaulted(arg:x:)' declared here}}{{none}}
510+
511+ let _ = variadic { return ( ) }
512+ // expected-error@-1:22 {{trailing closure passed to parameter of type 'String' that does not accept a closure}}{{none}}
513+ let _ = defaulted { return ( ) }
514+ // expected-error@-1:23 {{trailing closure passed to parameter of type 'String' that does not accept a closure}}{{none}}
515+ }
516+ // Trailing closure considered fulfilled by 'arg'; has function type.
517+ do {
518+ func variadic( arg: ( ( Int ) -> Void ) ... ) { }
519+ func defaulted( arg: ( ( Int ) -> Void ) = { _ in } ) { }
520+
521+ let _ = variadic { return ( ) }
522+ // expected-error@-1:22 {{contextual type for closure argument list expects 1 argument, which cannot be implicitly ignored}}{{23-23= _ in}}
523+ let _ = defaulted { return ( ) }
524+ // expected-error@-1:23 {{contextual type for closure argument list expects 1 argument, which cannot be implicitly ignored}}{{24-24= _ in}}
525+ }
526+ }
0 commit comments