@@ -2354,7 +2354,7 @@ bool FailureDiagnosis::diagnoseNonEscapingParameterToEscaping(
2354
2354
InFlightDiagnostic note = CS.TC .diagnose (
2355
2355
paramDecl->getLoc (), diag::noescape_parameter, paramDecl->getName ());
2356
2356
2357
- if (!srcFT ->isAutoClosure ()) {
2357
+ if (!paramDecl ->isAutoClosure ()) {
2358
2358
note.fixItInsert (paramDecl->getTypeLoc ().getSourceRange ().Start ,
2359
2359
" @escaping " );
2360
2360
} // TODO: add in a fixit for autoclosure
@@ -2971,7 +2971,13 @@ typeCheckArgumentChildIndependently(Expr *argExpr, Type argType,
2971
2971
// punt on passing down the type information, since type checking the
2972
2972
// subexpression won't be able to find the default argument provider.
2973
2973
if (argType) {
2974
- if (auto argTT = argType->getAs <TupleType>()) {
2974
+ if (auto *PT = dyn_cast<ParenType>(argType.getPointer ())) {
2975
+ const auto &flags = PT->getParameterFlags ();
2976
+ if (flags.isAutoClosure ()) {
2977
+ auto resultTy = PT->castTo <FunctionType>()->getResult ();
2978
+ argType = ParenType::get (PT->getASTContext (), resultTy);
2979
+ }
2980
+ } else if (auto argTT = argType->getAs <TupleType>()) {
2975
2981
if (auto scalarElt = getElementForScalarInitOfArg (argTT, candidates)) {
2976
2982
// If we found the single argument being initialized, use it.
2977
2983
auto &arg = argTT->getElement (*scalarElt);
@@ -2981,6 +2987,8 @@ typeCheckArgumentChildIndependently(Expr *argExpr, Type argType,
2981
2987
// the individual varargs argument, not the overall array type.
2982
2988
if (arg.isVararg ())
2983
2989
argType = arg.getVarargBaseTy ();
2990
+ else if (arg.isAutoClosure ())
2991
+ argType = arg.getType ()->castTo <FunctionType>()->getResult ();
2984
2992
else
2985
2993
argType = arg.getType ();
2986
2994
} else if (candidatesHaveAnyDefaultValues (candidates)) {
@@ -3047,6 +3055,11 @@ typeCheckArgumentChildIndependently(Expr *argExpr, Type argType,
3047
3055
3048
3056
// Look at each of the arguments assigned to this parameter.
3049
3057
auto currentParamType = param.getOldType ();
3058
+
3059
+ if (param.isAutoClosure ())
3060
+ currentParamType =
3061
+ currentParamType->castTo <FunctionType>()->getResult ();
3062
+
3050
3063
for (auto inArgNo : paramBindings[paramIdx]) {
3051
3064
// Determine the argument type.
3052
3065
auto currentArgType = TE->getElement (inArgNo);
@@ -3713,9 +3726,8 @@ class ArgumentMatcher : public MatchCallArgumentListener {
3713
3726
Ty = param.getPlainType ();
3714
3727
}
3715
3728
// @autoclosure; the type should be the result type.
3716
- if (auto FT = param.getOldType ()->getAs <AnyFunctionType>())
3717
- if (FT->isAutoClosure ())
3718
- Ty = FT->getResult ();
3729
+ if (param.isAutoClosure ())
3730
+ Ty = param.getPlainType ()->castTo <FunctionType>()->getResult ();
3719
3731
insertText << " <#" << Ty << " #>" ;
3720
3732
if (argIdx == 0 && insertableEndIdx != 0 )
3721
3733
insertText << " , " ;
@@ -7881,12 +7893,6 @@ FailureDiagnosis::validateContextualType(Type contextualType,
7881
7893
if (!contextualType)
7882
7894
return {contextualType, CTP};
7883
7895
7884
- // If we're asked to convert to an autoclosure, then we really want to
7885
- // convert to the result of it.
7886
- if (auto *FT = contextualType->getAs <AnyFunctionType>())
7887
- if (FT->isAutoClosure ())
7888
- contextualType = FT->getResult ();
7889
-
7890
7896
// Since some of the contextual types might be tuples e.g. subscript argument
7891
7897
// is a tuple or paren wrapping a tuple, it's required to recursively check
7892
7898
// its elements to determine nullability of the contextual type, because it
0 commit comments