[Completion] Avoid using unbound contextual type in argument completion

Match the logic in `getTypeForCompletion` and avoid using an unbound
generic type as the expected type for a completion.

rdar://155420395
This commit is contained in:
Hamish Knight
2025-07-08 21:30:45 +01:00
parent 8bf8b54fe6
commit 91222b9ebe
3 changed files with 18 additions and 1 deletions

View File

@@ -148,7 +148,9 @@ void ArgumentTypeCheckCompletionCallback::sawSolutionImpl(const Solution &S) {
ExpectedCallType = ContextualType;
}
}
if (ExpectedCallType && ExpectedCallType->hasUnresolvedType()) {
if (ExpectedCallType &&
(ExpectedCallType->hasUnresolvedType() ||
ExpectedCallType->hasUnboundGenericType())) {
ExpectedCallType = Type();
}

View File

@@ -1443,3 +1443,14 @@ struct NestedCallsWithoutClosingParen {
_ = (foo(#^IN_TUPLE?check=NESTED_CALL_WITHOUT_TYPE_RELATION^#, 1)
}
}
func testUnboundContextualType() {
struct S<T> {
func bar(x: Int) -> Self { self }
}
func foo(x: S<Int>) {
let _: S = x.bar(#^ARG_WITH_UNBOUND_CONTEXTUAL_TY^#
// ARG_WITH_UNBOUND_CONTEXTUAL_TY: Decl[InstanceMethod]/CurrNominal/Flair[ArgLabels]: ['(']{#x: Int#}[')'][#S<Int>#]; name=x:
}
}

View File

@@ -0,0 +1,4 @@
// {"kind":"complete","signature":"swift::ide::CodeCompletionResultType::calculateTypeRelation(swift::ide::ExpectedTypeContext const*, swift::DeclContext const*, swift::ide::USRBasedTypeContext const*) const"}
// RUN: %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s
func b(a : Array<Int>) {
let: Array = a.prefix( #^^#