Skip to content

Commit 736ed5b

Browse files
authored
Merge pull request #82911 from hamishknight/unbounded-6.2
[6.2] [Completion] Avoid using unbound contextual type in argument completion
2 parents 0cd265d + c562306 commit 736ed5b

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

lib/IDE/ArgumentCompletion.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ void ArgumentTypeCheckCompletionCallback::sawSolutionImpl(const Solution &S) {
148148
ExpectedCallType = ContextualType;
149149
}
150150
}
151-
if (ExpectedCallType && ExpectedCallType->hasUnresolvedType()) {
151+
if (ExpectedCallType &&
152+
(ExpectedCallType->hasUnresolvedType() ||
153+
ExpectedCallType->hasUnboundGenericType())) {
152154
ExpectedCallType = Type();
153155
}
154156

lib/IDE/CodeCompletionResultType.cpp

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

396-
ASSERT(!Ty->hasUnboundGenericType() && !ExpectedTy->hasUnboundGenericType());
397-
ASSERT(!ExpectedTy->hasTypeParameter());
396+
if (Ty->hasUnboundGenericType() || ExpectedTy->hasUnboundGenericType()) {
397+
CONDITIONAL_ASSERT(false && "Must not have unbound generic type here");
398+
return TypeRelation::Unrelated;
399+
}
400+
if (ExpectedTy->hasTypeParameter()) {
401+
CONDITIONAL_ASSERT(false && "Must not have generic type here");
402+
return TypeRelation::Unrelated;
403+
}
398404

399405
if (Ty->isEqual(ExpectedTy))
400406
return TypeRelation::Convertible;

test/IDE/complete_call_arg.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,3 +1443,14 @@ struct NestedCallsWithoutClosingParen {
14431443
_ = (foo(#^IN_TUPLE?check=NESTED_CALL_WITHOUT_TYPE_RELATION^#, 1)
14441444
}
14451445
}
1446+
1447+
func testUnboundContextualType() {
1448+
struct S<T> {
1449+
func bar(x: Int) -> Self { self }
1450+
}
1451+
1452+
func foo(x: S<Int>) {
1453+
let _: S = x.bar(#^ARG_WITH_UNBOUND_CONTEXTUAL_TY^#
1454+
// ARG_WITH_UNBOUND_CONTEXTUAL_TY: Decl[InstanceMethod]/CurrNominal/Flair[ArgLabels]: ['(']{#x: Int#}[')'][#S<Int>#]; name=x:
1455+
}
1456+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// {"kind":"complete","signature":"swift::ide::CodeCompletionResultType::calculateTypeRelation(swift::ide::ExpectedTypeContext const*, swift::DeclContext const*, swift::ide::USRBasedTypeContext const*) const"}
2+
// RUN: %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s
3+
func b(a : Array<Int>) {
4+
let: Array = a.prefix( #^^#

0 commit comments

Comments
 (0)