[CodeCompletion] Fix dot completion with non-nominals

Completion after dot inside an init (or any other parent expr with a
nominal type) was incorrectly looking at the types of parent expressions
whenever the base type was not a nominal (even an lvalue of a nominal
wasn't working).  This code to look at the type of the parent was never
correct, and fortunately the type-checking issues that prompted it to be
added in the first place have since been fixed, so we can just delete
it.

rdar://problem/25773358
This commit is contained in:
Ben Langmuir
2016-06-21 15:05:41 -07:00
parent 864bb61e93
commit 1c00cd9637
2 changed files with 28 additions and 23 deletions

View File

@@ -4887,37 +4887,17 @@ void CodeCompletionCallbacksImpl::doneParsing() {
case CompletionKind::DotExpr: {
Lookup.setHaveDot(DotLoc);
Type OriginalType = *ExprType;
Type ExprType = OriginalType;
// If there is no nominal type in the expr, try to find nominal types
// in the ancestors of the expr.
if (!OriginalType->getAnyNominal()) {
ExprParentFinder Walker(ParsedExpr, [&](ASTNode Node) {
if (auto E = Node.dyn_cast<Expr *>()) {
return E->getType() && E->getType()->getAnyNominal();
} else {
return false;
}
});
CurDeclContext->walkContext(Walker);
if (auto PCE = Walker.ParentClosest.dyn_cast<Expr *>()) {
ExprType = PCE->getType();
} else {
ExprType = OriginalType;
}
}
if (isDynamicLookup(ExprType))
if (isDynamicLookup(*ExprType))
Lookup.setIsDynamicLookup();
Lookup.initializeArchetypeTransformer(CurDeclContext, ExprType);
Lookup.initializeArchetypeTransformer(CurDeclContext, *ExprType);
CodeCompletionTypeContextAnalyzer TypeAnalyzer(CurDeclContext, ParsedExpr);
llvm::SmallVector<Type, 2> PossibleTypes;
if (TypeAnalyzer.Analyze(PossibleTypes)) {
Lookup.setExpectedTypes(PossibleTypes);
}
Lookup.getValueExprCompletions(ExprType, ReferencedDecl.getDecl());
Lookup.getValueExprCompletions(*ExprType, ReferencedDecl.getDecl());
break;
}