Skip to content

Commit 0ff5f60

Browse files
authored
Merge pull request #34110 from rintaro/ide-completion-rdar69308207
[LookupVisibleDecls] Use correct BaseTy to check the decls are applicable
2 parents 3016a89 + 77a76c9 commit 0ff5f60

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

lib/Sema/LookupVisibleDecls.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,11 +693,13 @@ static void lookupVisibleMemberDeclsImpl(
693693
}
694694
}
695695

696+
auto lookupTy = BaseTy;
697+
696698
const auto synthesizeAndLookupTypeMembers = [&](NominalTypeDecl *NTD) {
697699
synthesizeMemberDeclsForLookup(NTD, CurrDC);
698700

699701
// Look in for members of a nominal type.
700-
lookupTypeMembers(BaseTy, BaseTy, Consumer, CurrDC, LS, Reason);
702+
lookupTypeMembers(BaseTy, lookupTy, Consumer, CurrDC, LS, Reason);
701703
};
702704

703705
llvm::SmallPtrSet<ClassDecl *, 8> Ancestors;
@@ -725,7 +727,7 @@ static void lookupVisibleMemberDeclsImpl(
725727
Ancestors.insert(CD);
726728

727729
Reason = getReasonForSuper(Reason);
728-
BaseTy = CD->getSuperclass();
730+
lookupTy = CD->getSuperclass();
729731

730732
LS = LS.withOnSuperclass();
731733
if (CD->inheritsSuperclassInitializers())
@@ -734,7 +736,7 @@ static void lookupVisibleMemberDeclsImpl(
734736

735737
// Look into the inheritance chain.
736738
do {
737-
const auto CurClass = BaseTy->getClassOrBoundGenericClass();
739+
const auto CurClass = lookupTy->getClassOrBoundGenericClass();
738740

739741
// FIXME: This path is no substitute for an actual circularity check.
740742
// The real fix is to check that the superclass doesn't introduce a
@@ -744,10 +746,10 @@ static void lookupVisibleMemberDeclsImpl(
744746

745747
synthesizeAndLookupTypeMembers(CurClass);
746748

747-
BaseTy = CurClass->getSuperclass();
749+
lookupTy = CurClass->getSuperclass();
748750
if (!CurClass->inheritsSuperclassInitializers())
749751
LS = LS.withoutInheritsSuperclassInitializers();
750-
} while (BaseTy);
752+
} while (lookupTy);
751753
}
752754

753755
swift::DynamicLookupInfo::DynamicLookupInfo(

test/IDE/complete_sr13574.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %swift-ide-test -code-completion -source-filename %s -code-completion-token=OVERRIDE | %FileCheck %s --check-prefix=OVERRIDE
2+
// RUN: %swift-ide-test -code-completion -source-filename %s -code-completion-token=MEMBER | %FileCheck %s --check-prefix=MEMBER
3+
4+
class Root {
5+
func onRoot() {}
6+
}
7+
8+
class Base<T: Hashable>: Root {
9+
func onBase() -> T {}
10+
}
11+
12+
class Derived<T: Hashable>: Base<T> {
13+
func onDerived() {}
14+
15+
func #^OVERRIDE^#
16+
// OVERRIDE: Begin completions, 2 items
17+
// OVERRIDE-DAG: Decl[InstanceMethod]/Super/Erase[5]: override func onBase() -> T {|};
18+
// OVERRIDE-DAG: Decl[InstanceMethod]/Super/Erase[5]: override func onRoot() {|};
19+
// OVERRIDE-DAG: End completions
20+
21+
}
22+
23+
func testMember(val: Derived<Int>) {
24+
val.#^MEMBER^#
25+
// MEMBER: Begin completions, 4 items
26+
// MEMBER-DAG: Keyword[self]/CurrNominal: self[#Derived<Int>#]; name=self
27+
// MEMBER-DAG: Decl[InstanceMethod]/CurrNominal: onDerived()[#Void#]; name=onDerived()
28+
// MEMBER-DAG: Decl[InstanceMethod]/Super: onBase()[#Int#]; name=onBase()
29+
// MEMBER-DAG: Decl[InstanceMethod]/Super: onRoot()[#Void#]; name=onRoot()
30+
// MEMBER: End completions
31+
}

0 commit comments

Comments
 (0)