Skip to content

Commit 4203c2f

Browse files
committed
[Diagnostics] Store synthesized arguments in missing arguments diagnostic
Since we are about to start diagnosing more than just closures, we need information about what synthesized arguments look like.
1 parent 96598d8 commit 4203c2f

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3598,14 +3598,15 @@ bool MissingArgumentsFailure::diagnoseClosure(ClosureExpr *closure) {
35983598
if (!funcType)
35993599
return false;
36003600

3601-
auto diff = funcType->getNumParams() - NumSynthesized;
3601+
unsigned numSynthesized = SynthesizedArgs.size();
3602+
auto diff = funcType->getNumParams() - numSynthesized;
36023603

36033604
// If the closure didn't specify any arguments and it is in a context that
36043605
// needs some, produce a fixit to turn "{...}" into "{ _,_ in ...}".
36053606
if (diff == 0) {
36063607
auto diag =
36073608
emitDiagnostic(closure->getStartLoc(),
3608-
diag::closure_argument_list_missing, NumSynthesized);
3609+
diag::closure_argument_list_missing, numSynthesized);
36093610

36103611
std::string fixText; // Let's provide fixits for up to 10 args.
36113612
if (funcType->getNumParams() <= 10) {
@@ -3649,9 +3650,9 @@ bool MissingArgumentsFailure::diagnoseClosure(ClosureExpr *closure) {
36493650
llvm::raw_svector_ostream OS(fixIt);
36503651

36513652
OS << ",";
3652-
for (unsigned i = 0; i != NumSynthesized; ++i) {
3653+
for (unsigned i = 0; i != numSynthesized; ++i) {
36533654
OS << ((onlyAnonymousParams) ? "_" : "<#arg#>");
3654-
OS << ((i == NumSynthesized - 1) ? " " : ",");
3655+
OS << ((i == numSynthesized - 1) ? " " : ",");
36553656
}
36563657

36573658
diag.fixItInsertAfter(params->getEndLoc(), OS.str());

lib/Sema/CSDiagnostics.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,12 +1186,14 @@ class ImplicitInitOnNonConstMetatypeFailure final
11861186
class MissingArgumentsFailure final : public FailureDiagnostic {
11871187
using Param = AnyFunctionType::Param;
11881188

1189-
unsigned NumSynthesized;
1189+
SmallVector<Param, 4> SynthesizedArgs;
11901190

11911191
public:
11921192
MissingArgumentsFailure(Expr *root, ConstraintSystem &cs,
1193-
unsigned numSynthesized, ConstraintLocator *locator)
1194-
: FailureDiagnostic(root, cs, locator), NumSynthesized(numSynthesized) {}
1193+
ArrayRef<Param> synthesizedArgs,
1194+
ConstraintLocator *locator)
1195+
: FailureDiagnostic(root, cs, locator),
1196+
SynthesizedArgs(synthesizedArgs.begin(), synthesizedArgs.end()) {}
11951197

11961198
bool diagnoseAsError() override;
11971199

lib/Sema/CSFix.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,8 @@ AllowClosureParamDestructuring::create(ConstraintSystem &cs,
478478

479479
bool AddMissingArguments::diagnose(Expr *root, bool asNote) const {
480480
auto &cs = getConstraintSystem();
481-
MissingArgumentsFailure failure(root, cs, NumSynthesized, getLocator());
481+
MissingArgumentsFailure failure(root, cs, getSynthesizedArguments(),
482+
getLocator());
482483
return failure.diagnose(asNote);
483484
}
484485

0 commit comments

Comments
 (0)