Skip to content

Commit 4702f82

Browse files
committed
[CodeCompletion] Check getContextualType in getTypeForCompletion
1 parent 5d20113 commit 4702f82

File tree

4 files changed

+8
-17
lines changed

4 files changed

+8
-17
lines changed

lib/IDE/ExprCompletion.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,7 @@ void ExprTypeCheckCompletionCallback::sawSolutionImpl(
7777
const constraints::Solution &S) {
7878
auto &CS = S.getConstraintSystem();
7979

80-
Type ExpectedTy;
81-
if (auto ContextualType = S.getContextualType(CompletionExpr)) {
82-
ExpectedTy = ContextualType;
83-
} else {
84-
ExpectedTy = getTypeForCompletion(S, CompletionExpr);
85-
}
80+
Type ExpectedTy = getTypeForCompletion(S, CompletionExpr);
8681

8782
bool ImplicitReturn = isImplicitSingleExpressionReturn(CS, CompletionExpr);
8883

lib/IDE/PostfixCompletion.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,7 @@ void PostfixCompletionCallback::sawSolutionImpl(
176176
return;
177177

178178
auto *Locator = CS.getConstraintLocator(SemanticExpr);
179-
Type ExpectedTy;
180-
if (auto ContextualType = S.getContextualType(CompletionExpr)) {
181-
ExpectedTy = ContextualType;
182-
} else {
183-
ExpectedTy = getTypeForCompletion(S, CompletionExpr);
184-
}
179+
Type ExpectedTy = getTypeForCompletion(S, CompletionExpr);
185180
Expr *ParentExpr = CS.getParentExpr(CompletionExpr);
186181

187182
auto *CalleeLocator = S.getCalleeLocator(Locator);

lib/IDE/TypeCheckCompletionCallback.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ void TypeCheckCompletionCallback::fallbackTypeCheck(DeclContext *DC) {
4747

4848
Type swift::ide::getTypeForCompletion(const constraints::Solution &S,
4949
ASTNode Node) {
50+
if (auto ContextualType = S.getContextualType(Node)) {
51+
return ContextualType;
52+
}
53+
5054
if (!S.hasType(Node)) {
5155
assert(false && "Expression wasn't type checked?");
5256
return nullptr;
@@ -60,9 +64,6 @@ Type swift::ide::getTypeForCompletion(const constraints::Solution &S,
6064
Result = S.getResolvedType(Node);
6165
}
6266

63-
if (!Result || Result->is<UnresolvedType>())
64-
Result = S.getContextualType(Node);
65-
6667
if (Result && Result->is<UnresolvedType>()) {
6768
Result = Type();
6869
}

test/IDE/complete_constructor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ class DependentTypeInClosure<Data: DataType> {
312312
func testDependentTypeInClosure() {
313313
let _: DependentTypeInClosure = .#^DEPENDENT_IN_CLOSURE_3^#
314314
// DEPENDENT_IN_CLOSURE_3: Begin completions, 2 items
315-
// DEPENDENT_IN_CLOSURE_3-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Convertible]: init({#(arg): DataType#}, {#fn: (Data.Content) -> Void##(Data.Content) -> Void#})[#DependentTypeInClosure<DataType>#];
316-
// DEPENDENT_IN_CLOSURE_3-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Convertible]: init({#arg: DataType#}, {#fn: () -> Data.Content##() -> Data.Content#})[#DependentTypeInClosure<DataType>#];
315+
// DEPENDENT_IN_CLOSURE_3-DAG: Decl[Constructor]/CurrNominal: init({#(arg): DataType#}, {#fn: (DataType.Content) -> Void##(DataType.Content) -> Void#})[#DependentTypeInClosure<DataType>#];
316+
// DEPENDENT_IN_CLOSURE_3-DAG: Decl[Constructor]/CurrNominal: init({#arg: DataType#}, {#fn: () -> DataType.Content##() -> DataType.Content#})[#DependentTypeInClosure<DataType>#];
317317

318318
let _ = DependentTypeInClosure(#^DEPENDENT_IN_CLOSURE_1^#)
319319
// DEPENDENT_IN_CLOSURE_1-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ['(']{#(arg): DataType#}, {#fn: (_) -> Void##(_) -> Void#}[')'][#DependentTypeInClosure<DataType>#];

0 commit comments

Comments
 (0)