mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user