Skip to content

Commit 04aba44

Browse files
committed
[CodeCompletion] Don't emit member type construction for the same type
in unresolved member completion. e.g. struct Node { typealias Child = Node init(children: [Child]) {} } let node: Node = .#^COMPLETE^# This used to emit `.init(children:)` and `.Child(children:)`.
1 parent 54f2aa3 commit 04aba44

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3825,7 +3825,12 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
38253825
// convertible to the contextual type.
38263826
if (auto CD = dyn_cast<TypeDecl>(VD)) {
38273827
declTy = declTy->getMetatypeInstanceType();
3828-
return declTy->isEqual(T) || swift::isConvertibleTo(declTy, T, *DC);
3828+
3829+
// Emit construction for the same type via typealias doesn't make sense
3830+
// because we are emitting all `.init()`s.
3831+
if (declTy->isEqual(T))
3832+
return false;
3833+
return swift::isConvertibleTo(declTy, T, *DC);
38293834
}
38303835

38313836
// Only static member can be referenced.

test/IDE/complete_unresolved_members.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,12 @@ struct AnotherTy: MyProtocol {}
443443
func testSubType() {
444444
var _: BaseClass = .#^SUBTYPE_1^#
445445
}
446-
// SUBTYPE_1: Begin completions, 4 items
446+
// SUBTYPE_1: Begin completions, 3 items
447447
// SUBTYPE_1-NOT: init(failable:
448+
// SUBTYPE_1-NOT: Concrete1(
448449
// SUBTYPE_1-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Identical]: init()[#BaseClass#];
449450
// SUBTYPE_1-DAG: Decl[Constructor]/CurrNominal/TypeRelation[Convertible]: SubClass()[#BaseClass.SubClass#];
450451
// SUBTYPE_1-DAG: Decl[StaticVar]/CurrNominal/TypeRelation[Convertible]: subInstance[#BaseClass.SubClass#];
451-
// SUBTYPE_1-DAG: Decl[Constructor]/Super/TypeRelation[Identical]: Concrete1()[#BaseClass#];
452452
// SUBTYPE_1: End completions
453453

454454
func testMemberTypealias() {

0 commit comments

Comments
 (0)