Skip to content

Commit f47f5c4

Browse files
committed
[CSDiag] Adds a new diagnostic for implicit propertyWrapper initializer
1 parent 5e528de commit f47f5c4

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4521,6 +4521,9 @@ WARNING(property_wrapper_init_initialValue,none,
45214521
())
45224522
ERROR(property_wrapper_projection_value_missing,none,
45234523
"could not find projection value property %0", (Identifier))
4524+
ERROR(property_wrapper_missing_arg_init, none, "missing argument for parameter "
4525+
"%0 in property wrapper initializer; add 'wrappedValue' and %0 "
4526+
"arguments in '@%1(...)'", (Identifier, StringRef))
45244527

45254528
//------------------------------------------------------------------------------
45264529
// MARK: function builder diagnostics

lib/Sema/CSDiag.cpp

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

3244-
if (argIdx != 0) {
3245-
if (isPropertyWrapperImplicitInit()) {
3246-
insertText << "(";
3247-
} else {
3248-
insertText << ", ";
3249-
}
3250-
}
3244+
if (argIdx != 0)
3245+
insertText << ", ";
32513246
if (!name.empty())
32523247
insertText << name.str() << ": ";
32533248
Type Ty = param.getOldType();
@@ -3262,9 +3257,6 @@ class ArgumentMatcher : public MatchCallArgumentListener {
32623257
insertText << "<#" << Ty << "#>";
32633258
if (argIdx == 0 && insertableEndIdx != 0)
32643259
insertText << ", ";
3265-
if (isPropertyWrapperImplicitInit()) {
3266-
insertText << ")";
3267-
}
32683260

32693261
SourceLoc insertLoc;
32703262
if (argIdx > insertableEndIdx) {
@@ -3275,9 +3267,6 @@ class ArgumentMatcher : public MatchCallArgumentListener {
32753267
// fn(x: 1) { return 1 }
32763268
// is diagnosed as "missing argument for 'y'" (missingParamIdx 1).
32773269
// It should be "missing argument for 'z'" (missingParamIdx 2).
3278-
} else if (isPropertyWrapperImplicitInit()) {
3279-
insertLoc =
3280-
Lexer::getLocForEndOfToken(TC.Context.SourceMgr, FnExpr->getLoc());
32813270
} else if (auto *TE = dyn_cast<TupleExpr>(ArgExpr)) {
32823271
// fn():
32833272
// fn([argMissing])
@@ -3340,13 +3329,20 @@ class ArgumentMatcher : public MatchCallArgumentListener {
33403329

33413330
assert(insertLoc.isValid() && "missing argument after trailing closure?");
33423331

3343-
if (name.empty())
3332+
if (name.empty()) {
33443333
TC.diagnose(insertLoc, diag::missing_argument_positional,
33453334
missingParamIdx + 1)
33463335
.fixItInsert(insertLoc, insertText.str());
3347-
else
3348-
TC.diagnose(insertLoc, diag::missing_argument_named, name)
3349-
.fixItInsert(insertLoc, insertText.str());
3336+
} else {
3337+
if (isPropertyWrapperImplicitInit()) {
3338+
auto TE = cast<TypeExpr>(FnExpr);
3339+
TC.diagnose(TE->getLoc(), diag::property_wrapper_missing_arg_init, name,
3340+
TE->getInstanceType()->getString());
3341+
} else {
3342+
TC.diagnose(insertLoc, diag::missing_argument_named, name)
3343+
.fixItInsert(insertLoc, insertText.str());
3344+
}
3345+
}
33503346

33513347
auto candidate = CandidateInfo[0];
33523348
if (candidate.getDecl())

test/decl/var/property_wrappers.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ struct InvalidPropertyDelegateUse {
10951095
// SR-11060
10961096

10971097
class SR_11060_Class {
1098-
@SR_11060_Wrapper var property: Int = 1234 // expected-error {{missing argument for parameter 'string' in call}}{{20-20=(string: <#String#>)}}
1098+
@SR_11060_Wrapper var property: Int = 1234 // expected-error {{missing argument for parameter 'string' in property wrapper initializer; add 'wrappedValue' and 'string' arguments in '@SR_11060_Wrapper(...)'}}
10991099
}
11001100

11011101
@propertyWrapper
@@ -1106,3 +1106,4 @@ struct SR_11060_Wrapper {
11061106
self.wrappedValue = wrappedValue
11071107
}
11081108
}
1109+

0 commit comments

Comments
 (0)