Skip to content

Commit 89a8e2d

Browse files
[Sema] Allow optional hole propagation in code completion mode
1 parent 5ab264a commit 89a8e2d

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,11 +1993,16 @@ bool TypeVariableBinding::attempt(ConstraintSystem &cs) const {
19931993
// without any contextual information, so even though `x` would get
19941994
// bound to result type of the chain, underlying type variable wouldn't
19951995
// be resolved, so we need to propagate holes up the conversion chain.
1996-
if (TypeVar->getImpl().canBindToHole() &&
1997-
srcLocator->directlyAt<OptionalEvaluationExpr>()) {
1998-
if (auto objectTy = type->getOptionalObjectType()) {
1999-
if (auto *typeVar = objectTy->getAs<TypeVariableType>())
2000-
cs.recordPotentialHole(typeVar);
1996+
// Also propagate in code completion mode because in some cases code
1997+
// completion relies on type variable being a potential hole.
1998+
if (TypeVar->getImpl().canBindToHole()) {
1999+
if (srcLocator->directlyAt<OptionalEvaluationExpr>() ||
2000+
cs.isForCodeCompletion()) {
2001+
if (auto objectTy = type->getOptionalObjectType()) {
2002+
if (auto *typeVar = objectTy->getAs<TypeVariableType>()) {
2003+
cs.recordPotentialHole(typeVar);
2004+
}
2005+
}
20012006
}
20022007
}
20032008

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %swift-ide-test -code-completion -source-filename %s -code-completion-token COMPLETE | %FileCheck %s
2+
3+
struct Foo {
4+
var x: Int = {
5+
guard let foo = #^COMPLETE^#
6+
}()
7+
}
8+
9+
// CHECK: Decl[Struct]/CurrModule: Foo[#Foo#];

0 commit comments

Comments
 (0)