Skip to content

Commit 676a48f

Browse files
committed
[QoI] Adapt new diagnostics to reverted portion of SE-0110 and new function input decomposition
1 parent 2fd247a commit 676a48f

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5994,29 +5994,23 @@ static bool isCastToTypedPointer(ConstraintSystem *CS, const Expr *Fn,
59945994
return true;
59955995
}
59965996

5997-
static bool diagnoseClosureExplicitParameterMismatch(ConstraintSystem *const CS,
5998-
SourceLoc loc,
5999-
Type paramType,
6000-
Type argType) {
6001-
SmallVector<Identifier, 4> argLabels;
6002-
gatherArgumentLabels(argType, argLabels);
6003-
6004-
auto params = decomposeParamType(paramType, nullptr, 0);
6005-
auto args = decomposeArgType(argType, argLabels);
6006-
5997+
static bool diagnoseClosureExplicitParameterMismatch(
5998+
ConstraintSystem *const CS, SourceLoc loc,
5999+
ArrayRef<AnyFunctionType::Param> params,
6000+
ArrayRef<AnyFunctionType::Param> args) {
60076001
// We are not trying to diagnose structural problems with top-level
60086002
// arguments here.
60096003
if (params.size() != args.size())
60106004
return false;
60116005

60126006
for (unsigned i = 0, n = params.size(); i != n; ++i) {
6013-
auto &paramType = params[i].Ty;
6014-
auto &argType = args[i].Ty;
6007+
auto paramType = params[i].getType();
6008+
auto argType = args[i].getType();
60156009

60166010
if (auto paramFnType = paramType->getAs<AnyFunctionType>()) {
60176011
if (auto argFnType = argType->getAs<AnyFunctionType>())
60186012
return diagnoseClosureExplicitParameterMismatch(
6019-
CS, loc, paramFnType->getInput(), argFnType->getInput());
6013+
CS, loc, paramFnType->getParams(), argFnType->getParams());
60206014
}
60216015

60226016
if (!paramType || !argType || isUnresolvedOrTypeVarType(paramType) ||
@@ -6137,12 +6131,13 @@ bool FailureDiagnosis::diagnoseTrailingClosureErrors(ApplyExpr *callExpr) {
61376131
return false;
61386132
}
61396133

6140-
if (auto fnType = paramType->getAs<AnyFunctionType>()) {
6141-
if (auto *params = closureExpr->getParameters()) {
6142-
auto closureParamType = params->getType(CS->getASTContext());
6143-
if (diagnoseClosureExplicitParameterMismatch(CS, params->getStartLoc(),
6144-
closureParamType,
6145-
fnType->getInput()))
6134+
if (auto paramFnType = paramType->getAs<AnyFunctionType>()) {
6135+
auto closureType = CS->getType(closureExpr);
6136+
if (auto *argFnType = closureType->getAs<AnyFunctionType>()) {
6137+
auto *params = closureExpr->getParameters();
6138+
auto loc = params ? params->getStartLoc() : closureExpr->getStartLoc();
6139+
if (diagnoseClosureExplicitParameterMismatch(
6140+
CS, loc, argFnType->getParams(), paramFnType->getParams()))
61466141
return true;
61476142
}
61486143
}

test/Constraints/tuple_arguments.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,9 +1547,7 @@ struct SR_5199 {}
15471547
extension Sequence where Iterator.Element == (key: String, value: String?) {
15481548
func f() -> [SR_5199] {
15491549
return self.map { (key, value) in
1550-
// expected-error@-1 {{closure tuple parameter '(key: String, value: Optional<String>)' does not support destructuring}} {23-35=(arg) -> SR_5199}} {{9-9=\n let (key, value) = arg\n return }}
1551-
SR_5199()
1550+
SR_5199() // Ok
15521551
}
15531552
}
15541553
}
1555-

0 commit comments

Comments
 (0)