Skip to content

Commit 232e4a4

Browse files
authored
Merge pull request #23332 from rintaro/ide-completion-conformance-rdar36594731
[AST] Don't return decls from unsatisfied conformance
2 parents 5d2b1b1 + dcb1db2 commit 232e4a4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/Sema/LookupVisibleDecls.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,18 @@ static void lookupDeclsFromProtocolsBeingConformedTo(
388388
NominalTypeDecl *CurrNominal = BaseTy->getAnyNominal();
389389
if (!CurrNominal)
390390
return;
391+
ModuleDecl *Module = FromContext->getParentModule();
391392

392393
for (auto Conformance : CurrNominal->getAllConformances()) {
393394
auto Proto = Conformance->getProtocol();
394395
if (!Proto->isAccessibleFrom(FromContext))
395396
continue;
396397

398+
// Skip unsatisfied conditional conformances.
399+
if (Conformance->getConditionalRequirementsIfAvailable() &&
400+
!Module->conformsToProtocol(BaseTy, Proto))
401+
continue;
402+
397403
DeclVisibilityKind ReasonForThisProtocol;
398404
if (Reason == DeclVisibilityKind::MemberOfCurrentNominal)
399405
ReasonForThisProtocol =

test/IDE/complete_constrained.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,31 @@ extension MyStruct {
4848
func concreteExt_None_TConformsToSomeProto<U>(_ x: U) -> Int where T: SomeProto { return 1 }
4949
}
5050

51+
protocol Proto_Int {}
52+
extension Proto_Int {
53+
func conditional_Int() -> Int { return 1 }
54+
}
55+
protocol Proto_String {}
56+
extension Proto_String {
57+
func conditional_String() -> Int { return 1 }
58+
}
59+
extension MyStruct: Proto_Int where T == Int{}
60+
extension MyStruct: Proto_String where T == String {}
61+
5162
func foo(s: MyStruct<Int>) {
5263
let _ = s.#^MYSTRUCT_INT_DOT^#
53-
// MYSTRUCT_INT_DOT: Begin completions, 6 items
64+
// MYSTRUCT_INT_DOT: Begin completions, 7 items
5465
// MYSTRUCT_INT_DOT-DAG: Keyword[self]/CurrNominal: self[#MyStruct<Int>#]; name=self
5566
// MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/CurrNominal: methodWithConstrainedGenericParam({#x: SomeProto#})[#Int#]; name=methodWithConstrainedGenericParam(x: SomeProto)
5667
// MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/CurrNominal: concreteExt_TEqInt_None()[#Int#]; name=concreteExt_TEqInt_None()
5768
// MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/CurrNominal: concreteExt_None_TEqInt({#(x): U#})[#Int#]; name=concreteExt_None_TEqInt(x: U)
5869
// MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/Super: protoExt_AssocEqInt_None()[#Int#]; name=protoExt_AssocEqInt_None()
5970
// MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/Super: protoExt_None_AssocEqInt({#(x): U#})[#Int#]; name=protoExt_None_AssocEqInt(x: U)
71+
// MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/Super: conditional_Int()[#Int#]; name=conditional_Int()
6072
// MYSTRUCT_INT_DOT: End completions
6173

6274
let _ = MyStruct<Int>.#^META_MYSTRUCT_INT_DOT^#
63-
// META_MYSTRUCT_INT_DOT: Begin completions, 10 items
75+
// META_MYSTRUCT_INT_DOT: Begin completions, 11 items
6476
// META_MYSTRUCT_INT_DOT-DAG: Keyword[self]/CurrNominal: self[#MyStruct<Int>.Type#]; name=self
6577
// META_MYSTRUCT_INT_DOT-DAG: Keyword/CurrNominal: Type[#MyStruct<Int>.Type#]; name=Type
6678
// META_MYSTRUCT_INT_DOT-DAG: Decl[TypeAlias]/CurrNominal: Assoc[#T#]; name=Assoc
@@ -71,6 +83,7 @@ func foo(s: MyStruct<Int>) {
7183
// META_MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/CurrNominal: concreteExt_None_TEqInt({#(self): MyStruct<Int>#})[#(U) -> Int#]; name=concreteExt_None_TEqInt(self: MyStruct<Int>)
7284
// META_MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/Super: protoExt_AssocEqInt_None({#(self): MyStruct<Int>#})[#() -> Int#]; name=protoExt_AssocEqInt_None(self: MyStruct<Int>)
7385
// META_MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/Super: protoExt_None_AssocEqInt({#(self): MyStruct<Int>#})[#(U) -> Int#]; name=protoExt_None_AssocEqInt(self: MyStruct<Int>)
86+
// META_MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/Super: conditional_Int({#(self): MyStruct<Int>#})[#() -> Int#]; name=conditional_Int(self: MyStruct<Int>)
7487
// META_MYSTRUCT_INT_DOT: End completions
7588
}
7689

0 commit comments

Comments
 (0)