Skip to content

Commit 0beddca

Browse files
committed
Unify diagnose invalid attr producing
1 parent f9b1a52 commit 0beddca

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,28 +2411,29 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
24112411
attrs.clearAttribute(TAK_autoclosure);
24122412
}
24132413

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+
24142427
for (auto i : FunctionAttrs) {
24152428
if (!attrs.has(i))
24162429
continue;
24172430

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) {
24232435
diag.fixItRemove(
24242436
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-
}
24362437
}
24372438
attrs.clearAttribute(i);
24382439
}

0 commit comments

Comments
 (0)