Skip to content

Commit b08fb12

Browse files
authored
Merge pull request #16288 from nathawes/rdar38153332-code-completion-hits-unreachable-in-matchtypes-4.2
2 parents ac38f00 + 6556dbe commit b08fb12

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -939,10 +939,15 @@ static CodeCompletionResult::ExpectedTypeRelation calculateTypeRelation(
939939
Ty->is<ErrorType>() ||
940940
ExpectedTy->is<ErrorType>())
941941
return CodeCompletionResult::ExpectedTypeRelation::Unrelated;
942-
if (Ty->isEqual(ExpectedTy))
943-
return CodeCompletionResult::ExpectedTypeRelation::Identical;
944-
if (isConvertibleTo(Ty, ExpectedTy, *DC))
945-
return CodeCompletionResult::ExpectedTypeRelation::Convertible;
942+
943+
// Equality/Conversion of GenericTypeParameterType won't account for
944+
// requirements – ignore them
945+
if (!Ty->hasTypeParameter() && !ExpectedTy->hasTypeParameter()) {
946+
if (Ty->isEqual(ExpectedTy))
947+
return CodeCompletionResult::ExpectedTypeRelation::Identical;
948+
if (isConvertibleTo(Ty, ExpectedTy, *DC))
949+
return CodeCompletionResult::ExpectedTypeRelation::Convertible;
950+
}
946951
if (auto FT = Ty->getAs<AnyFunctionType>()) {
947952
if (FT->getResult()->isVoid())
948953
return CodeCompletionResult::ExpectedTypeRelation::Invalid;

test/IDE/complete_call_arg.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=BOUND_IUO | %FileCheck %s -check-prefix=MEMBEROF_IUO
4646
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=FORCED_IUO | %FileCheck %s -check-prefix=MEMBEROF_IUO
4747

48+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENERIC_TO_GENERIC | %FileCheck %s -check-prefix=GENERIC_TO_GENERIC
49+
4850
var i1 = 1
4951
var i2 = 2
5052
var oi1 : Int?
@@ -373,6 +375,14 @@ struct TestBoundGeneric1 {
373375
// BOUND_GENERIC_1: Decl[InstanceVar]/CurrNominal: y[#[Int]#];
374376
}
375377

378+
func whereConvertible<T>(lhs: T, rhs: T) where T: Collection {
379+
_ = zip(lhs, #^GENERIC_TO_GENERIC^#)
380+
}
381+
// GENERIC_TO_GENERIC: Begin completions
382+
// GENERIC_TO_GENERIC: Decl[LocalVar]/Local: lhs[#Collection#]; name=lhs
383+
// GENERIC_TO_GENERIC: Decl[LocalVar]/Local: rhs[#Collection#]; name=rhs
384+
// GENERIC_TO_GENERIC: End completions
385+
376386
func emptyOverload() {}
377387
func emptyOverload(foo foo: Int) {}
378388
emptyOverload(foo: #^EMPTY_OVERLOAD_1^#)

0 commit comments

Comments
 (0)