|
16 | 16 | #include "swift/AST/Decl.h"
|
17 | 17 | #include "swift/AST/DiagnosticEngine.h"
|
18 | 18 | #include "swift/AST/DiagnosticsFrontend.h"
|
| 19 | +#include "swift/AST/ExistentialLayout.h" |
19 | 20 | #include "swift/AST/Module.h"
|
20 | 21 | #include "swift/AST/ModuleLoader.h"
|
21 | 22 | #include "swift/AST/NameLookup.h"
|
@@ -85,18 +86,24 @@ static bool declIsPrivate(const Decl *member) {
|
85 | 86 | }
|
86 | 87 |
|
87 | 88 | static bool extendedTypeIsPrivate(TypeLoc inheritedType) {
|
88 |
| - if (!inheritedType.getType()) |
| 89 | + auto type = inheritedType.getType(); |
| 90 | + if (!type) |
89 | 91 | return true;
|
90 | 92 |
|
91 |
| - if (!inheritedType.getType()->isExistentialType()) { |
| 93 | + if (!type->isExistentialType()) { |
92 | 94 | // Be conservative. We don't know how to deal with other extended types.
|
93 | 95 | return false;
|
94 | 96 | }
|
95 | 97 |
|
96 |
| - SmallVector<ProtocolDecl *, 2> protocols; |
97 |
| - inheritedType.getType()->getExistentialTypeProtocols(protocols); |
| 98 | + auto layout = type->getExistentialLayout(); |
| 99 | + assert(!layout.superclass && "Should not have a subclass existential " |
| 100 | + "in the inheritance clause of an extension"); |
| 101 | + for (auto protoTy : layout.getProtocols()) { |
| 102 | + if (!declIsPrivate(protoTy->getDecl())) |
| 103 | + return false; |
| 104 | + } |
98 | 105 |
|
99 |
| - return std::all_of(protocols.begin(), protocols.end(), declIsPrivate); |
| 106 | + return true; |
100 | 107 | }
|
101 | 108 |
|
102 | 109 | static std::string mangleTypeAsContext(const NominalTypeDecl *type) {
|
@@ -172,6 +179,8 @@ bool swift::emitReferenceDependencies(DiagnosticEngine &diags,
|
172 | 179 | break;
|
173 | 180 | }
|
174 | 181 |
|
| 182 | + // Check if the extension is just adding members, or if it is |
| 183 | + // introducing a conformance to a public protocol. |
175 | 184 | bool justMembers = std::all_of(ED->getInherited().begin(),
|
176 | 185 | ED->getInherited().end(),
|
177 | 186 | extendedTypeIsPrivate);
|
|
0 commit comments