diff --git a/lib/Sema/CSDiag.cpp b/lib/Sema/CSDiag.cpp index 3558188f6e2dd..1910e242ce091 100644 --- a/lib/Sema/CSDiag.cpp +++ b/lib/Sema/CSDiag.cpp @@ -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(argExpr) || - (isa(argExpr) && - cast(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. // diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index df3bd12ac70d2..b8cf4a95a75bb 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -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(getRawAnchor())) { + auto *TE = dyn_cast(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;