Skip to content

Commit 6b62ac8

Browse files
committed
[CSDiag] Switch expression diagnostics to check @autoclosure from parameter flags
There is only one place where we need to do that - `typeCheckArgumentChildIndependently`
1 parent b3f8625 commit 6b62ac8

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,7 +2354,7 @@ bool FailureDiagnosis::diagnoseNonEscapingParameterToEscaping(
23542354
InFlightDiagnostic note = CS.TC.diagnose(
23552355
paramDecl->getLoc(), diag::noescape_parameter, paramDecl->getName());
23562356

2357-
if (!srcFT->isAutoClosure()) {
2357+
if (!paramDecl->isAutoClosure()) {
23582358
note.fixItInsert(paramDecl->getTypeLoc().getSourceRange().Start,
23592359
"@escaping ");
23602360
} // TODO: add in a fixit for autoclosure
@@ -2971,7 +2971,13 @@ typeCheckArgumentChildIndependently(Expr *argExpr, Type argType,
29712971
// punt on passing down the type information, since type checking the
29722972
// subexpression won't be able to find the default argument provider.
29732973
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>()) {
29752981
if (auto scalarElt = getElementForScalarInitOfArg(argTT, candidates)) {
29762982
// If we found the single argument being initialized, use it.
29772983
auto &arg = argTT->getElement(*scalarElt);
@@ -2981,6 +2987,8 @@ typeCheckArgumentChildIndependently(Expr *argExpr, Type argType,
29812987
// the individual varargs argument, not the overall array type.
29822988
if (arg.isVararg())
29832989
argType = arg.getVarargBaseTy();
2990+
else if (arg.isAutoClosure())
2991+
argType = arg.getType()->castTo<FunctionType>()->getResult();
29842992
else
29852993
argType = arg.getType();
29862994
} else if (candidatesHaveAnyDefaultValues(candidates)) {
@@ -3047,6 +3055,11 @@ typeCheckArgumentChildIndependently(Expr *argExpr, Type argType,
30473055

30483056
// Look at each of the arguments assigned to this parameter.
30493057
auto currentParamType = param.getOldType();
3058+
3059+
if (param.isAutoClosure())
3060+
currentParamType =
3061+
currentParamType->castTo<FunctionType>()->getResult();
3062+
30503063
for (auto inArgNo : paramBindings[paramIdx]) {
30513064
// Determine the argument type.
30523065
auto currentArgType = TE->getElement(inArgNo);
@@ -3713,9 +3726,8 @@ class ArgumentMatcher : public MatchCallArgumentListener {
37133726
Ty = param.getPlainType();
37143727
}
37153728
// @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();
37193731
insertText << "<#" << Ty << "#>";
37203732
if (argIdx == 0 && insertableEndIdx != 0)
37213733
insertText << ", ";
@@ -7881,12 +7893,6 @@ FailureDiagnosis::validateContextualType(Type contextualType,
78817893
if (!contextualType)
78827894
return {contextualType, CTP};
78837895

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-
78907896
// Since some of the contextual types might be tuples e.g. subscript argument
78917897
// is a tuple or paren wrapping a tuple, it's required to recursively check
78927898
// its elements to determine nullability of the contextual type, because it

0 commit comments

Comments
 (0)