@@ -2241,33 +2241,9 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2241
2241
rep = FunctionType::Representation::Swift;
2242
2242
} else {
2243
2243
rep = *parsedRep;
2244
-
2245
- if (attrs.has (TAK_autoclosure)) {
2246
- // @convention(c) and @convention(block) are not allowed with an @autoclosure type.
2247
- if (rep == FunctionType::Representation::CFunctionPointer ||
2248
- rep == FunctionType::Representation::Block) {
2249
- diagnose (attrs.getLoc (TAK_convention),
2250
- diag::invalid_autoclosure_and_convention_attributes,
2251
- attrs.getConventionName ());
2252
- attrs.clearAttribute (TAK_convention);
2253
- }
2254
- }
2255
2244
}
2256
2245
}
2257
2246
2258
- // @autoclosure is only valid on parameters.
2259
- if (!isParam && attrs.has (TAK_autoclosure)) {
2260
- bool isVariadicFunctionParam =
2261
- options.is (TypeResolverContext::VariadicFunctionInput) &&
2262
- !options.hasBase (TypeResolverContext::EnumElementDecl);
2263
-
2264
- diagnose (attrs.getLoc (TAK_autoclosure),
2265
- isVariadicFunctionParam ? diag::attr_not_on_variadic_parameters
2266
- : diag::attr_only_on_parameters,
2267
- " @autoclosure" );
2268
- attrs.clearAttribute (TAK_autoclosure);
2269
- }
2270
-
2271
2247
if (attrs.has (TAK_differentiable) &&
2272
2248
!Context.LangOpts .EnableExperimentalDifferentiableProgramming ) {
2273
2249
diagnose (attrs.getLoc (TAK_differentiable),
@@ -2287,6 +2263,28 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2287
2263
}
2288
2264
}
2289
2265
2266
+ // Validate use of @autoclosure
2267
+ if (attrs.has (TAK_autoclosure)) {
2268
+ if (attrs.hasConvention ()) {
2269
+ if (attrs.getConventionName () == " c" ||
2270
+ attrs.getConventionName () == " block" ) {
2271
+ diagnose (attrs.getLoc (TAK_convention),
2272
+ diag::invalid_autoclosure_and_convention_attributes,
2273
+ attrs.getConventionName ());
2274
+ attrs.clearAttribute (TAK_convention);
2275
+ }
2276
+ } else if (options.is (TypeResolverContext::VariadicFunctionInput) &&
2277
+ !options.hasBase (TypeResolverContext::EnumElementDecl)) {
2278
+ diagnose (attrs.getLoc (TAK_autoclosure),
2279
+ diag::attr_not_on_variadic_parameters, " @autoclosure" );
2280
+ attrs.clearAttribute (TAK_autoclosure);
2281
+ } else if (!options.is (TypeResolverContext::FunctionInput)) {
2282
+ diagnose (attrs.getLoc (TAK_autoclosure), diag::attr_only_on_parameters,
2283
+ " @autoclosure" );
2284
+ attrs.clearAttribute (TAK_autoclosure);
2285
+ }
2286
+ }
2287
+
2290
2288
auto instanceOptions = options;
2291
2289
instanceOptions.setContext (None);
2292
2290
0 commit comments