@@ -1056,3 +1056,64 @@ func test_inout_with_invalid_member_ref() {
1056
1056
// expected-error@-1 {{value of tuple type 'Void' has no member 'createS'}}
1057
1057
// expected-error@-2 {{cannot pass immutable value as inout argument: '$0' is immutable}}
1058
1058
}
1059
+
1060
+ struct SR12033 < T> {
1061
+ public static func capture( _ thunk: ( ) -> T ) -> SR12033 < T > {
1062
+ . init( )
1063
+ }
1064
+ public static func captureA( _ thunk: @autoclosure ( ) -> T ) -> SR12033 < T > { // expected-note{{'captureA' declared here}}
1065
+ . init( )
1066
+ }
1067
+ public static func captureE( _ thunk: @escaping ( ) -> T ) -> SR12033 < T > {
1068
+ . init( )
1069
+ }
1070
+ public static func captureAE( _ thunk: @autoclosure @escaping ( ) -> T ) -> SR12033 < T > { // expected-note{{'captureAE' declared here}}
1071
+ . init( )
1072
+ }
1073
+ }
1074
+
1075
+ var number = 1
1076
+
1077
+ let t = SR12033 < Int > . capture { number } // OK
1078
+ let t2 = SR12033 < Int > . captureE { number } // OK
1079
+ let t3 = SR12033< Int> . captureA( number) // OK
1080
+
1081
+ let e = SR12033 < Int > . captureA { number }
1082
+ // expected-error@-1{{trailing closure passed to parameter of type 'Int' that does not accept a closure}}
1083
+ let e2 = SR12033 < Int > . captureAE { number }
1084
+ // expected-error@-1{{trailing closure passed to parameter of type 'Int' that does not accept a closure}}
1085
+
1086
+ struct SR12033_S {
1087
+ public static var zero : SR12033_S { . init( ) }
1088
+
1089
+ // captureGenericFuncA
1090
+ public static func f< T> ( _ thunk: @autoclosure ( ) -> T ) -> SR12033_S { // expected-note 2{{'f' declared here}}
1091
+ // expected-note@-1 2{{in call to function 'f'}}
1092
+ . init( )
1093
+ }
1094
+
1095
+ public static func unwrap< T> ( _ optional: T ? , _ defaultValue: @autoclosure ( ) throws -> T ) { }
1096
+
1097
+ func test( ) {
1098
+ let number = 1
1099
+ _ = Self . f ( number) // OK
1100
+ _ = Self . f { number } // expected-error{{trailing closure passed to parameter of type '_' that does not accept a closure}}
1101
+ // expected-error@-1 {{generic parameter 'T' could not be inferred}}
1102
+ _ = Self . f { _ in number } // expected-error{{trailing closure passed to parameter of type '_' that does not accept a closure}}
1103
+ // expected-error@-1 {{generic parameter 'T' could not be inferred}}
1104
+ }
1105
+
1106
+ // Inference with contextual type is OK `T` is infered as `() -> Int`
1107
+ func test( _ o: ( ( ) -> Int ) ? ) {
1108
+ Self . unwrap ( o, { 0 } ) // Ok
1109
+ Self . unwrap ( o, { . zero } ) // Ok
1110
+ Self . unwrap ( o, { _ in . zero } ) // expected-error {{contextual closure type '() -> Int' expects 0 arguments, but 1 was used in closure body}}
1111
+ }
1112
+
1113
+ // `T` is infered as `() -> U`
1114
+ func testGeneric< U> ( _ o: ( ( ) -> U ) ? ) where U: BinaryInteger {
1115
+ Self . unwrap ( o, { . zero } ) // OK
1116
+ Self . unwrap ( o, { 0 } ) // OK
1117
+ Self . unwrap ( o, { _ in . zero } ) // expected-error {{contextual closure type '() -> U' expects 0 arguments, but 1 was used in closure body}}
1118
+ }
1119
+ }
0 commit comments