[CodeCompletion] Don't add empty code completion on invalid init

For now, just avoid adding the completion since that will assert later
when we try to sort. In the future we could actually complete something
useful here, since we can dig out the names of the parameters even if
the type is invalid.

rdar://problem/22834017

Swift SVN r32211
This commit is contained in:
Ben Langmuir
2015-09-24 22:13:13 +00:00
parent 50df5852c3
commit be016aedf3
2 changed files with 32 additions and 9 deletions

View File

@@ -1733,26 +1733,36 @@ public:
->getResult()
->castTo<AnyFunctionType>();
bool needInit = false;
if (IsSuperRefExpr) {
assert(addName.empty());
assert(isa<ConstructorDecl>(CurrDeclContext) &&
"can call super.init only inside a constructor");
needInit = true;
} else if (addName.empty() && HaveDot &&
Reason == DeclVisibilityKind::MemberOfCurrentNominal) {
// This case is querying the init function as member
needInit = true;
}
// If we won't be able to provide a result, bail out.
if (MemberType->is<ErrorType>() && addName.empty() && !needInit)
return;
// Add the constructor, possibly including any default arguments.
auto addConstructorImpl = [&](bool includeDefaultArgs = true) {
CodeCompletionResultBuilder Builder(
Sink, CodeCompletionResult::ResultKind::Declaration,
getSemanticContext(CD, Reason), ExpectedTypes);
Builder.setAssociatedDecl(CD);
if (IsSuperRefExpr) {
if (needInit) {
assert(addName.empty());
assert(isa<ConstructorDecl>(CurrDeclContext) &&
"can call super.init only inside a constructor");
addLeadingDot(Builder);
Builder.addTextChunk("init");
} else if (!addName.empty()) {
Builder.addTextChunk(addName.str());
} else if (HaveDot &&
Reason == DeclVisibilityKind::MemberOfCurrentNominal) {
// This case is querying the init function as member
assert(addName.empty());
Builder.addTextChunk("init");
} else {
assert(!MemberType->is<ErrorType>() && "will insert empty result");
}
if (MemberType->is<ErrorType>()) {