@@ -1410,9 +1410,9 @@ static bool isDefaultNoEscapeContext(const DeclContext *DC) {
1410
1410
}
1411
1411
1412
1412
// Hack to apply context-specific @escaping to an AST function type.
1413
- static Type adjustFunctionExtInfo (DeclContext *DC,
1414
- Type ty,
1415
- TypeResolutionOptions options) {
1413
+ static Type applyNonEscapingFromContext (DeclContext *DC,
1414
+ Type ty,
1415
+ TypeResolutionOptions options) {
1416
1416
// Remember whether this is a function parameter.
1417
1417
bool isFunctionParam =
1418
1418
options.contains (TR_FunctionInput) ||
@@ -1426,7 +1426,11 @@ static Type adjustFunctionExtInfo(DeclContext *DC,
1426
1426
if (defaultNoEscape && !extInfo.isNoEscape ()) {
1427
1427
extInfo = extInfo.withNoEscape ();
1428
1428
1429
- // We lost the sugar to flip the isNoEscape bit
1429
+ // We lost the sugar to flip the isNoEscape bit.
1430
+ //
1431
+ // FIXME: It would be better to add a new AttributedType sugared type,
1432
+ // which would wrap the NameAliasType or ParenType, and apply the
1433
+ // isNoEscape bit when de-sugaring.
1430
1434
return FunctionType::get (funcTy->getInput (), funcTy->getResult (), extInfo);
1431
1435
}
1432
1436
@@ -1467,7 +1471,7 @@ Type TypeChecker::resolveIdentifierType(
1467
1471
// Hack to apply context-specific @escaping to a typealias with an underlying
1468
1472
// function type.
1469
1473
if (result->is <FunctionType>())
1470
- result = adjustFunctionExtInfo (DC, result, options);
1474
+ result = applyNonEscapingFromContext (DC, result, options);
1471
1475
1472
1476
// We allow a type to conform to a protocol that is less available than
1473
1477
// the type itself. This enables a type to retroactively model or directly
@@ -1716,7 +1720,7 @@ Type TypeResolver::resolveType(TypeRepr *repr, TypeResolutionOptions options) {
1716
1720
// Default non-escaping for closure parameters
1717
1721
auto result = resolveASTFunctionType (cast<FunctionTypeRepr>(repr), options);
1718
1722
if (result && result->is <FunctionType>())
1719
- return adjustFunctionExtInfo (DC, result, options);
1723
+ return applyNonEscapingFromContext (DC, result, options);
1720
1724
return result;
1721
1725
}
1722
1726
return resolveSILFunctionType (cast<FunctionTypeRepr>(repr), options);
@@ -1973,10 +1977,6 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
1973
1977
.fixItReplace (resultRange, " Never" );
1974
1978
}
1975
1979
1976
- if (attrs.has (TAK_noescape)) {
1977
- // FIXME: diagnostic to tell user this is redundant and drop it
1978
- }
1979
-
1980
1980
// Resolve the function type directly with these attributes.
1981
1981
FunctionType::ExtInfo extInfo (rep,
1982
1982
attrs.has (TAK_autoclosure),
@@ -2016,7 +2016,7 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2016
2016
attrs.clearAttribute (TAK_escaping);
2017
2017
} else {
2018
2018
// No attribute; set the isNoEscape bit if we're in parameter context.
2019
- ty = adjustFunctionExtInfo (DC, ty, options);
2019
+ ty = applyNonEscapingFromContext (DC, ty, options);
2020
2020
}
2021
2021
}
2022
2022
@@ -2034,6 +2034,7 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2034
2034
}
2035
2035
}
2036
2036
} else if (hasFunctionAttr && fnRepr) {
2037
+ // Remove the function attributes from the set so that we don't diagnose.
2037
2038
for (auto i : FunctionAttrs)
2038
2039
attrs.clearAttribute (i);
2039
2040
attrs.convention = None;
@@ -2484,6 +2485,11 @@ Type TypeResolver::resolveTupleType(TupleTypeRepr *repr,
2484
2485
2485
2486
// If this is the top level of a function input list, peel off the
2486
2487
// ImmediateFunctionInput marker and install a FunctionInput one instead.
2488
+ //
2489
+ // If we have a single ParenType though, don't clear these bits; we
2490
+ // still want to parse the type contained therein as if it were in
2491
+ // parameter position, meaning function types are not @escaping by
2492
+ // default.
2487
2493
auto elementOptions = options;
2488
2494
if (!repr->isParenType ()) {
2489
2495
elementOptions = withoutContext (elementOptions);
0 commit comments