@@ -1410,9 +1410,9 @@ static bool isDefaultNoEscapeContext(const DeclContext *DC) {
14101410}
14111411
14121412// 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) {
14161416 // Remember whether this is a function parameter.
14171417 bool isFunctionParam =
14181418 options.contains (TR_FunctionInput) ||
@@ -1426,7 +1426,12 @@ static Type adjustFunctionExtInfo(DeclContext *DC,
14261426 if (defaultNoEscape && !extInfo.isNoEscape ()) {
14271427 extInfo = extInfo.withNoEscape ();
14281428
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.
1434+ // <https://bugs.swift.org/browse/SR-2520>
14301435 return FunctionType::get (funcTy->getInput (), funcTy->getResult (), extInfo);
14311436 }
14321437
@@ -1467,7 +1472,7 @@ Type TypeChecker::resolveIdentifierType(
14671472 // Hack to apply context-specific @escaping to a typealias with an underlying
14681473 // function type.
14691474 if (result->is <FunctionType>())
1470- result = adjustFunctionExtInfo (DC, result, options);
1475+ result = applyNonEscapingFromContext (DC, result, options);
14711476
14721477 // We allow a type to conform to a protocol that is less available than
14731478 // the type itself. This enables a type to retroactively model or directly
@@ -1716,7 +1721,7 @@ Type TypeResolver::resolveType(TypeRepr *repr, TypeResolutionOptions options) {
17161721 // Default non-escaping for closure parameters
17171722 auto result = resolveASTFunctionType (cast<FunctionTypeRepr>(repr), options);
17181723 if (result && result->is <FunctionType>())
1719- return adjustFunctionExtInfo (DC, result, options);
1724+ return applyNonEscapingFromContext (DC, result, options);
17201725 return result;
17211726 }
17221727 return resolveSILFunctionType (cast<FunctionTypeRepr>(repr), options);
@@ -1973,10 +1978,6 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
19731978 .fixItReplace (resultRange, " Never" );
19741979 }
19751980
1976- if (attrs.has (TAK_noescape)) {
1977- // FIXME: diagnostic to tell user this is redundant and drop it
1978- }
1979-
19801981 // Resolve the function type directly with these attributes.
19811982 FunctionType::ExtInfo extInfo (rep,
19821983 attrs.has (TAK_autoclosure),
@@ -2016,7 +2017,7 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
20162017 attrs.clearAttribute (TAK_escaping);
20172018 } else {
20182019 // No attribute; set the isNoEscape bit if we're in parameter context.
2019- ty = adjustFunctionExtInfo (DC, ty, options);
2020+ ty = applyNonEscapingFromContext (DC, ty, options);
20202021 }
20212022 }
20222023
@@ -2034,6 +2035,7 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
20342035 }
20352036 }
20362037 } else if (hasFunctionAttr && fnRepr) {
2038+ // Remove the function attributes from the set so that we don't diagnose.
20372039 for (auto i : FunctionAttrs)
20382040 attrs.clearAttribute (i);
20392041 attrs.convention = None;
@@ -2484,6 +2486,11 @@ Type TypeResolver::resolveTupleType(TupleTypeRepr *repr,
24842486
24852487 // If this is the top level of a function input list, peel off the
24862488 // ImmediateFunctionInput marker and install a FunctionInput one instead.
2489+ //
2490+ // If we have a single ParenType though, don't clear these bits; we
2491+ // still want to parse the type contained therein as if it were in
2492+ // parameter position, meaning function types are not @escaping by
2493+ // default.
24872494 auto elementOptions = options;
24882495 if (!repr->isParenType ()) {
24892496 elementOptions = withoutContext (elementOptions);
0 commit comments