Skip to content

[CSDiag] Add a new diagnostic for @propertyWrapper implicit init call missing arguments #26219

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 7 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
30 changes: 28 additions & 2 deletions lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3241,8 +3241,13 @@ class ArgumentMatcher : public MatchCallArgumentListener {
SmallString<32> insertBuf;
llvm::raw_svector_ostream insertText(insertBuf);

if (argIdx != 0)
insertText << ", ";
if (argIdx != 0) {
if (isPropertyWrapperImplicitInit()) {
insertText << "(";
} else {
insertText << ", ";
}
}
if (!name.empty())
insertText << name.str() << ": ";
Type Ty = param.getOldType();
Expand All @@ -3257,6 +3262,9 @@ class ArgumentMatcher : public MatchCallArgumentListener {
insertText << "<#" << Ty << "#>";
if (argIdx == 0 && insertableEndIdx != 0)
insertText << ", ";
if (isPropertyWrapperImplicitInit()) {
insertText << ")";
}

SourceLoc insertLoc;
if (argIdx > insertableEndIdx) {
Expand All @@ -3267,6 +3275,9 @@ class ArgumentMatcher : public MatchCallArgumentListener {
// fn(x: 1) { return 1 }
// is diagnosed as "missing argument for 'y'" (missingParamIdx 1).
// It should be "missing argument for 'z'" (missingParamIdx 2).
} else if (isPropertyWrapperImplicitInit()) {
insertLoc =
Lexer::getLocForEndOfToken(TC.Context.SourceMgr, FnExpr->getLoc());
} else if (auto *TE = dyn_cast<TupleExpr>(ArgExpr)) {
// fn():
// fn([argMissing])
Expand Down Expand Up @@ -3345,6 +3356,21 @@ class ArgumentMatcher : public MatchCallArgumentListener {
Diagnosed = true;
}

bool isPropertyWrapperImplicitInit() {
if (auto TE = dyn_cast<TypeExpr>(FnExpr)) {
if (auto info = TE->getInstanceType()
->getAnyNominal()
->getPropertyWrapperTypeInfo()) {
if (auto parent = CandidateInfo.CS.getParentExpr(FnExpr)) {
if (auto CE = dyn_cast<CallExpr>(parent)) {
return CE->isImplicit();
}
}
}
}
return false;
}

bool missingLabel(unsigned paramIdx) override {
return false;
}
Expand Down
15 changes: 15 additions & 0 deletions test/decl/var/property_wrappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1091,3 +1091,18 @@ struct InvalidPropertyDelegateUse {
self.x.foo() // expected-error {{value of type 'Int' has no member 'foo'}}
}
}

// SR-11060

class SR_11060_Class {
@SR_11060_Wrapper var property: Int = 1234 // expected-error {{missing argument for parameter 'string' in call}}{{20-20=(string: <#String#>)}}
}

@propertyWrapper
struct SR_11060_Wrapper {
var wrappedValue: Int

init(wrappedValue: Int, string: String) { // expected-note {{'init(wrappedValue:string:)' declared here}}
self.wrappedValue = wrappedValue
}
}