Skip to content

Commit a3b6ac5

Browse files
committed
[CSDiag] Check for property wrapper implicit init when creating fix-it
1 parent 62a37d7 commit a3b6ac5

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,8 +3241,13 @@ class ArgumentMatcher : public MatchCallArgumentListener {
32413241
SmallString<32> insertBuf;
32423242
llvm::raw_svector_ostream insertText(insertBuf);
32433243

3244-
if (argIdx != 0)
3245-
insertText << ", ";
3244+
if (argIdx != 0) {
3245+
if (isPropertyWrapperImplicitInit()) {
3246+
insertText << "(";
3247+
} else {
3248+
insertText << ", ";
3249+
}
3250+
}
32463251
if (!name.empty())
32473252
insertText << name.str() << ": ";
32483253
Type Ty = param.getOldType();
@@ -3257,6 +3262,9 @@ class ArgumentMatcher : public MatchCallArgumentListener {
32573262
insertText << "<#" << Ty << "#>";
32583263
if (argIdx == 0 && insertableEndIdx != 0)
32593264
insertText << ", ";
3265+
if (isPropertyWrapperImplicitInit()) {
3266+
insertText << ")";
3267+
}
32603268

32613269
SourceLoc insertLoc;
32623270
if (argIdx > insertableEndIdx) {
@@ -3267,6 +3275,9 @@ class ArgumentMatcher : public MatchCallArgumentListener {
32673275
// fn(x: 1) { return 1 }
32683276
// is diagnosed as "missing argument for 'y'" (missingParamIdx 1).
32693277
// It should be "missing argument for 'z'" (missingParamIdx 2).
3278+
} else if (isPropertyWrapperImplicitInit()) {
3279+
insertLoc =
3280+
Lexer::getLocForEndOfToken(TC.Context.SourceMgr, FnExpr->getLoc());
32703281
} else if (auto *TE = dyn_cast<TupleExpr>(ArgExpr)) {
32713282
// fn():
32723283
// fn([argMissing])
@@ -3345,6 +3356,21 @@ class ArgumentMatcher : public MatchCallArgumentListener {
33453356
Diagnosed = true;
33463357
}
33473358

3359+
bool isPropertyWrapperImplicitInit() {
3360+
if (auto TE = dyn_cast<TypeExpr>(FnExpr)) {
3361+
if (auto info = TE->getInstanceType()
3362+
->getAnyNominal()
3363+
->getPropertyWrapperTypeInfo()) {
3364+
if (auto parent = CandidateInfo.CS.getParentExpr(FnExpr)) {
3365+
if (auto CE = dyn_cast<CallExpr>(parent)) {
3366+
return CE->isImplicit();
3367+
}
3368+
}
3369+
}
3370+
}
3371+
return false;
3372+
}
3373+
33483374
bool missingLabel(unsigned paramIdx) override {
33493375
return false;
33503376
}

0 commit comments

Comments
 (0)