Skip to content

Commit fbc7858

Browse files
authored
Merge pull request swiftlang#8911 from slavapestov/subclass-existentials-type-reconstruction
Add subclass existential support to type reconstruction
2 parents 137c496 + d96d488 commit fbc7858

File tree

5 files changed

+460
-317
lines changed

5 files changed

+460
-317
lines changed

lib/AST/USRGeneration.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,24 @@ static bool printObjCUSR(const ValueDecl *D, raw_ostream &OS) {
113113
return printObjCUSRFragment(D, ObjCName.second.getString(Buf), OS);
114114
}
115115

116-
static bool ShouldUseObjCUSR(const Decl *D) {
116+
static bool shouldUseObjCUSR(const Decl *D) {
117117
// Only the subscript getter/setter are visible to ObjC rather than the
118118
// subscript itself
119119
if (isa<SubscriptDecl>(D))
120120
return false;
121121

122122
auto Parent = D->getDeclContext()->getInnermostDeclarationDeclContext();
123-
if (Parent && (!ShouldUseObjCUSR(Parent) || // parent should be visible too
123+
if (Parent && (!shouldUseObjCUSR(Parent) || // parent should be visible too
124124
!D->getDeclContext()->isTypeContext() || // no local decls
125125
isa<TypeDecl>(D))) // nested types aren't supported
126126
return false;
127127

128128
if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
129+
if (auto *PD = dyn_cast<ProtocolDecl>(D))
130+
if (auto known = PD->getKnownProtocolKind())
131+
if (known == KnownProtocolKind::AnyObject)
132+
return false;
133+
129134
if (isa<EnumElementDecl>(VD))
130135
return true;
131136
return objc_translation::isVisibleToObjC(VD, Accessibility::Internal);
@@ -134,7 +139,7 @@ static bool ShouldUseObjCUSR(const Decl *D) {
134139
if (const ExtensionDecl *ED = dyn_cast<ExtensionDecl>(D)) {
135140
if (auto ExtendedType = ED->getExtendedType()) {
136141
auto baseClass = ExtendedType->getClassOrBoundGenericClass();
137-
return baseClass && ShouldUseObjCUSR(baseClass) && !baseClass->isForeign();
142+
return baseClass && shouldUseObjCUSR(baseClass) && !baseClass->isForeign();
138143
}
139144
}
140145
return false;
@@ -202,7 +207,7 @@ bool ide::printDeclUSR(const ValueDecl *D, raw_ostream &OS) {
202207
return Ignore;
203208
}
204209

205-
if (ShouldUseObjCUSR(D)) {
210+
if (shouldUseObjCUSR(D)) {
206211
return printObjCUSR(D, OS);
207212
}
208213

@@ -238,7 +243,7 @@ bool ide::printAccessorUSR(const AbstractStorageDecl *D, AccessorKind AccKind,
238243
// addressor.
239244

240245
AbstractStorageDecl *SD = const_cast<AbstractStorageDecl*>(D);
241-
if (ShouldUseObjCUSR(SD)) {
246+
if (shouldUseObjCUSR(SD)) {
242247
return printObjCUSRForAccessor(SD, AccKind, OS);
243248
}
244249

0 commit comments

Comments
 (0)