Skip to content

[Diagnostics] Add a special case diagnostic for call to init on `Void… #29504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1296,21 +1296,6 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
}
}

// Let's check whether this is a situation when callee expects
// no arguments but N are given. Otherwise, just below
// `typeCheckArgumentChild*` is going to use `()` is a contextual type which
// is incorrect.
if (argType && argType->isVoid()) {
auto *argExpr = callExpr->getArg();
if (isa<ParenExpr>(argExpr) ||
(isa<TupleExpr>(argExpr) &&
cast<TupleExpr>(argExpr)->getNumElements() > 0)) {
diagnose(callExpr->getLoc(), diag::extra_argument_to_nullary_call)
.highlight(argExpr->getSourceRange());
return true;
}
}

// Get the expression result of type checking the arguments to the call
// independently, so we have some idea of what we're working with.
//
Expand Down
16 changes: 15 additions & 1 deletion lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4561,7 +4561,21 @@ bool ExtraneousArgumentsFailure::diagnoseAsNote() {
}

bool ExtraneousArgumentsFailure::diagnoseSingleExtraArgument() const {
auto *arguments = getArgumentListExprFor(getLocator());
auto *locator = getLocator();

// This specifically handles a case of `Void(...)` which generates
// constraints differently from other constructor invocations and
// wouldn't have `ApplyArgument` as a last element in the locator.
if (auto *call = dyn_cast<CallExpr>(getRawAnchor())) {
auto *TE = dyn_cast<TypeExpr>(call->getFn());
if (TE && getType(TE)->getMetatypeInstanceType()->isVoid()) {
emitDiagnostic(call->getLoc(), diag::extra_argument_to_nullary_call)
.highlight(call->getArg()->getSourceRange());
return true;
}
}

auto *arguments = getArgumentListExprFor(locator);
if (!arguments)
return false;

Expand Down