Skip to content

Commit 5384712

Browse files
committed
[IDE/Complete] Fix a bug where 'indices' property from Collections doesn't show up for code-completion.
rdar://26642818
1 parent 9e8266a commit 5384712

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3302,6 +3302,8 @@ bool swift::isExtensionApplied(DeclContext &DC, Type BaseTy,
33023302
CreatedTC.reset(new TypeChecker(DC.getASTContext()));
33033303
TC = CreatedTC.get();
33043304
}
3305+
if (ED->getAsProtocolExtensionContext())
3306+
return TC->isProtocolExtensionUsable(&DC, BaseTy, const_cast<ExtensionDecl*>(ED));
33053307
ConstraintSystem CS(*TC, &DC, Options);
33063308
auto Loc = CS.getConstraintLocator(nullptr);
33073309
std::vector<Identifier> Scratch;

test/IDE/complete_from_constraint_extensions.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONSTRAINT1 | FileCheck %s -check-prefix=CONSTRAINT1
22
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONSTRAINT2 | FileCheck %s -check-prefix=CONSTRAINT2
3+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONSTRAINT3 | FileCheck %s -check-prefix=CONSTRAINT3
34

45
public protocol P1 {}
56
public protocol P2 {}
@@ -33,3 +34,20 @@ func foo2() {
3334
// CONSTRAINT2: Begin completions, 1 items
3435
// CONSTRAINT2-NEXT: Decl[InstanceMethod]/CurrNominal: P2Method()[#Void#]; name=P2Method()
3536
// CONSTRAINT2-NEXT: End completions
37+
38+
protocol MyIndexable {}
39+
protocol MyCollection : MyIndexable {
40+
associatedtype Indices = MyDefaultIndices<Self>
41+
var indices: Indices { get }
42+
}
43+
struct MyDefaultIndices<Elements : MyIndexable> : MyCollection {}
44+
extension MyCollection where Indices == MyDefaultIndices<Self> {
45+
var indices: MyDefaultIndices<Self> { return MyDefaultIndices() }
46+
}
47+
struct ConcreteCollection<Element> : MyCollection {}
48+
func foo3() {
49+
ConcreteCollection<Int>().#^CONSTRAINT3^#
50+
}
51+
// CONSTRAINT3: Begin completions, 1 items
52+
// CONSTRAINT3-NEXT: Decl[InstanceVar]/Super: indices[#MyDefaultIndices<ConcreteCollection<Int>>#]; name=indices
53+
// CONSTRAINT3-NEXT: End completions

0 commit comments

Comments
 (0)