Skip to content

Commit 6f026fb

Browse files
authored
Merge pull request #29504 from xedin/special-void-init-handling
[Diagnostics] Add a special case diagnostic for call to init on `Void…
2 parents 02b6161 + 38aded7 commit 6f026fb

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,21 +1296,6 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
12961296
}
12971297
}
12981298

1299-
// Let's check whether this is a situation when callee expects
1300-
// no arguments but N are given. Otherwise, just below
1301-
// `typeCheckArgumentChild*` is going to use `()` is a contextual type which
1302-
// is incorrect.
1303-
if (argType && argType->isVoid()) {
1304-
auto *argExpr = callExpr->getArg();
1305-
if (isa<ParenExpr>(argExpr) ||
1306-
(isa<TupleExpr>(argExpr) &&
1307-
cast<TupleExpr>(argExpr)->getNumElements() > 0)) {
1308-
diagnose(callExpr->getLoc(), diag::extra_argument_to_nullary_call)
1309-
.highlight(argExpr->getSourceRange());
1310-
return true;
1311-
}
1312-
}
1313-
13141299
// Get the expression result of type checking the arguments to the call
13151300
// independently, so we have some idea of what we're working with.
13161301
//

lib/Sema/CSDiagnostics.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4561,7 +4561,21 @@ bool ExtraneousArgumentsFailure::diagnoseAsNote() {
45614561
}
45624562

45634563
bool ExtraneousArgumentsFailure::diagnoseSingleExtraArgument() const {
4564-
auto *arguments = getArgumentListExprFor(getLocator());
4564+
auto *locator = getLocator();
4565+
4566+
// This specifically handles a case of `Void(...)` which generates
4567+
// constraints differently from other constructor invocations and
4568+
// wouldn't have `ApplyArgument` as a last element in the locator.
4569+
if (auto *call = dyn_cast<CallExpr>(getRawAnchor())) {
4570+
auto *TE = dyn_cast<TypeExpr>(call->getFn());
4571+
if (TE && getType(TE)->getMetatypeInstanceType()->isVoid()) {
4572+
emitDiagnostic(call->getLoc(), diag::extra_argument_to_nullary_call)
4573+
.highlight(call->getArg()->getSourceRange());
4574+
return true;
4575+
}
4576+
}
4577+
4578+
auto *arguments = getArgumentListExprFor(locator);
45654579
if (!arguments)
45664580
return false;
45674581

0 commit comments

Comments
 (0)