Skip to content

Commit 9edb7f9

Browse files
authored
Merge pull request #79790 from hamishknight/expectations
[Completion] Avoid type parameters in expected types
2 parents 67f312c + 4a2c612 commit 9edb7f9

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

lib/IDE/ArgumentCompletion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void ArgumentTypeCheckCompletionCallback::sawSolutionImpl(const Solution &S) {
139139
Type ExpectedCallType;
140140
if (auto ArgLoc = S.getConstraintSystem().getArgumentLocator(ParentCall)) {
141141
if (auto FuncArgApplyInfo = S.getFunctionArgApplyInfo(ArgLoc)) {
142-
Type ParamType = FuncArgApplyInfo->getParamInterfaceType();
142+
Type ParamType = FuncArgApplyInfo->getParamType();
143143
ExpectedCallType = S.simplifyTypeForCodeCompletion(ParamType);
144144
}
145145
}

lib/IDE/CodeCompletionResultType.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,16 @@ static TypeRelation calculateTypeRelation(Type Ty, Type ExpectedTy,
393393
return TypeRelation::Unknown;
394394
}
395395

396-
// Equality/Conversion of GenericTypeParameterType won't account for
397-
// requirements – ignore them
398-
if (!Ty->hasTypeParameter() && !ExpectedTy->hasTypeParameter()) {
399-
if (Ty->isEqual(ExpectedTy))
400-
return TypeRelation::Convertible;
396+
ASSERT(!Ty->hasUnboundGenericType() && !ExpectedTy->hasUnboundGenericType());
397+
ASSERT(!ExpectedTy->hasTypeParameter());
398+
399+
if (Ty->isEqual(ExpectedTy))
400+
return TypeRelation::Convertible;
401+
402+
// FIXME: We ought to be opening generic parameters present in completion
403+
// results for generic decls, and mapping into context types for non-generic
404+
// decls. For now, avoid attempting to compare.
405+
if (!Ty->hasTypeParameter()) {
401406
bool isAny = false;
402407
isAny |= ExpectedTy->isAny();
403408
isAny |= ExpectedTy->is<ArchetypeType>() &&

test/IDE/complete_rdar127844278.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ func foo<T>(@Builder _: () -> T) where T: Q {}
3131
foo {
3232
S(#^COMPLETE^#)
3333
}
34-
// COMPLETE-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ['(']{#a: Void#}[')'][#S<()>#]; name=a:
35-
// COMPLETE-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]: ['(']{#b: String#}[')'][#S<String>#]; name=b:
34+
// COMPLETE-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]/TypeRelation[Convertible]: ['(']{#a: Void#}[')'][#S<()>#]; name=a:
35+
// COMPLETE-DAG: Decl[Constructor]/CurrNominal/Flair[ArgLabels]/TypeRelation[Convertible]: ['(']{#b: String#}[')'][#S<String>#]; name=b:

0 commit comments

Comments
 (0)