@@ -2411,28 +2411,29 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2411
2411
attrs.clearAttribute (TAK_autoclosure);
2412
2412
}
2413
2413
2414
+ const auto diagnoseInvalidAttr = [&](TypeAttrKind kind) {
2415
+ if (kind == TAK_escaping) {
2416
+ Type optionalObjectType = ty->getOptionalObjectType ();
2417
+ if (optionalObjectType && optionalObjectType->is <AnyFunctionType>()) {
2418
+ return diagnoseInvalid (repr, attrs.getLoc (kind),
2419
+ diag::escaping_optional_type_argument);
2420
+ }
2421
+ }
2422
+ return diagnoseInvalid (repr, attrs.getLoc (kind),
2423
+ diag::attribute_requires_function_type,
2424
+ TypeAttributes::getAttrName (kind));
2425
+ };
2426
+
2414
2427
for (auto i : FunctionAttrs) {
2415
2428
if (!attrs.has (i))
2416
2429
continue ;
2417
2430
2418
- Type optionalObjectType = ty->getOptionalObjectType ();
2419
- if (i == TAK_escaping && optionalObjectType &&
2420
- optionalObjectType->is <AnyFunctionType>()) {
2421
- auto diag = diagnoseInvalid (repr, attrs.getLoc (i),
2422
- diag::escaping_optional_type_argument);
2431
+ auto diag = diagnoseInvalidAttr (i);
2432
+ // If we see @escaping among the attributes on this type, because it
2433
+ // isn't a function type, we'll remove it.
2434
+ if (i == TAK_escaping) {
2423
2435
diag.fixItRemove (
2424
2436
getTypeAttrRangeWithAt (Context, attrs.getLoc (TAK_escaping)));
2425
- } else {
2426
- auto diag = diagnoseInvalid (repr, attrs.getLoc (i),
2427
- diag::attribute_requires_function_type,
2428
- TypeAttributes::getAttrName (i));
2429
-
2430
- // If we see @escaping among the attributes on this type, because it
2431
- // isn't a function type, we'll remove it.
2432
- if (i == TAK_escaping) {
2433
- diag.fixItRemove (
2434
- getTypeAttrRangeWithAt (Context, attrs.getLoc (TAK_escaping)));
2435
- }
2436
2437
}
2437
2438
attrs.clearAttribute (i);
2438
2439
}
0 commit comments