Skip to content

Commit c8ad4cd

Browse files
authored
Merge pull request #38664 from ahoppen/pr/complete-typealias-from-protocol
[CodeCompletion] Complete typealias from inherited protocol
2 parents 1a7d987 + 37c06cd commit c8ad4cd

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lib/Sema/LookupVisibleDecls.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,12 @@ static void lookupDeclsFromProtocolsBeingConformedTo(
477477
if (!isDeclVisibleInLookupMode(VD, LS, FromContext))
478478
continue;
479479

480+
if (isa<TypeAliasDecl>(VD)) {
481+
// Typealias declarations of the protocol are always visible in
482+
// types that inherits from it.
483+
Consumer.foundDecl(VD, ReasonForThisProtocol);
484+
continue;
485+
}
480486
if (!VD->isProtocolRequirement())
481487
continue;
482488

test/IDE/complete_protocol_typealias.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,11 @@ func testGenericUnresolvedMember() {
5555
// GENERIC_UNRESOLVED_MEMBER: Begin completions, 1 item
5656
// GENERIC_UNRESOLVED_MEMBER-DAG: Decl[TypeAlias]/CurrNominal: Storage[#Array<T>#];
5757
// GENERIC_UNRESOLVED_MEMBER: End completions
58+
}
59+
60+
struct ConformingType: MyProto {
61+
func foo(content: #^GLOBAL_COMPLETE_IN_CONFORMING_TYPE^#) {}
62+
// GLOBAL_COMPLETE_IN_CONFORMING_TYPE: Begin completions
63+
// GLOBAL_COMPLETE_IN_CONFORMING_TYPE: Decl[TypeAlias]/Super: Content[#Int#];
64+
// GLOBAL_COMPLETE_IN_CONFORMING_TYPE: End completions
5865
}

test/IDE/complete_unresolved_members.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,13 @@ struct AnotherTy: MyProtocol {}
439439
func testSubType() {
440440
var _: BaseClass = .#^SUBTYPE_1^#
441441
}
442-
// SUBTYPE_1: Begin completions, 4 items
443-
// SUBTYPE_1-NOT: Concrete1(
442+
// SUBTYPE_1: Begin completions, 6 items
444443
// SUBTYPE_1-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Identical]: init()[#BaseClass#];
445444
// SUBTYPE_1-DAG: Decl[Class]/CurrNominal/TypeRelation[Convertible]: SubClass[#BaseClass.SubClass#];
446445
// SUBTYPE_1-DAG: Decl[StaticVar]/CurrNominal/TypeRelation[Convertible]: subInstance[#BaseClass.SubClass#];
447446
// SUBTYPE_1-DAG: Decl[Constructor]/CurrNominal: init({#failable: Void#})[#BaseClass?#];
447+
// SUBTYPE_1-DAG: Decl[TypeAlias]/Super/TypeRelation[Identical]: Concrete1[#BaseClass#];
448+
// SUBTYPE_1-DAG: Decl[TypeAlias]/Super: Concrete2[#AnotherTy#];
448449
// SUBTYPE_1: End completions
449450

450451
func testMemberTypealias() {

0 commit comments

Comments
 (0)