Skip to content

Commit 7f77733

Browse files
committed
Merge pull request #1137 from ahoppen/master
Fixes SR-642: Code completion does not instantiate generic arguments of a type wrapped in an optional.
2 parents 8dedfb3 + 6e45d6b commit 7f77733

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

include/swift/AST/Types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3152,7 +3152,7 @@ DEFINE_EMPTY_CAN_TYPE_WRAPPER(SILBlockStorageType, Type)
31523152

31533153
/// A type with a special syntax that is always sugar for a library type.
31543154
///
3155-
/// The prime examples are arrays (T[] -> Array<T>) and
3155+
/// The prime examples are arrays ([T] -> Array<T>) and
31563156
/// optionals (T? -> Optional<T>).
31573157
class SyntaxSugarType : public TypeBase {
31583158
Type Base;

lib/IDE/CodeCompletion.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,9 +1722,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
17221722
Type ContextTy = VD->getDeclContext()->getDeclaredTypeOfContext();
17231723
if (ContextTy) {
17241724
Type MaybeNominalType = ExprType->getRValueInstanceType();
1725-
if (ContextTy->getAnyNominal() == MaybeNominalType->getAnyNominal() &&
1725+
if (ContextTy->lookThroughAllAnyOptionalTypes()->getAnyNominal() ==
1726+
MaybeNominalType->lookThroughAllAnyOptionalTypes()->getAnyNominal() &&
17261727
!isBoringBoundGenericType(MaybeNominalType)) {
1727-
if (Type T = MaybeNominalType->getTypeOfMember(
1728+
if (Type T = MaybeNominalType->lookThroughAllAnyOptionalTypes()->getTypeOfMember(
17281729
CurrDeclContext->getParentModule(), VD, TypeResolver.get()))
17291730
return TransformerPt ? T.transform(TransformerPt->getTransformerFunc()) :
17301731
T;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=FOO_OPTIONAL_1 | FileCheck %s -check-prefix=FOO_OPTIONAL_1
2+
3+
struct Bar {
4+
}
5+
6+
struct Foo<T> {
7+
func myFunction(foobar: T) {
8+
}
9+
}
10+
11+
// SR-642 Code completion does not instantiate generic arguments of a type wrapped in an optional
12+
let x: Foo<Bar>? = Foo<Bar>()
13+
x.#^FOO_OPTIONAL_1^#
14+
// FOO_OPTIONAL_1: Begin completions, 4 items
15+
// FOO_OPTIONAL_1-DAG: Decl[InstanceMethod]/CurrNominal/Erase[1]: ?.myFunction({#(foobar): Bar#})[#Void#]; name=myFunction(foobar: Bar)
16+
// FOO_OPTIONAL_1: End completions

0 commit comments

Comments
 (0)