@@ -221,13 +221,21 @@ DefaultAndMaxAccessLevelRequest::evaluate(Evaluator &evaluator,
221
221
222
222
Optional<AccessScope> maxScope = AccessScope::getPublic ();
223
223
224
+ // Try to scope the extension's access to the least public type mentioned
225
+ // in its where clause.
224
226
for (auto *typeDecl : typeDecls) {
225
227
if (isa<TypeAliasDecl>(typeDecl) || isa<NominalTypeDecl>(typeDecl)) {
226
228
auto scope = typeDecl->getFormalAccessScope (ED->getDeclContext ());
227
229
maxScope = maxScope->intersectWith (scope);
228
230
}
229
231
}
230
232
233
+ // Now include the scope of the extended nominal type.
234
+ if (NominalTypeDecl *nominal = ED->getExtendedNominal ()) {
235
+ auto scope = nominal->getFormalAccessScope (ED->getDeclContext ());
236
+ maxScope = maxScope->intersectWith (scope);
237
+ }
238
+
231
239
if (!maxScope.hasValue ()) {
232
240
// This is an error case and will be diagnosed elsewhere.
233
241
maxAccess = AccessLevel::Public;
@@ -244,12 +252,6 @@ DefaultAndMaxAccessLevelRequest::evaluate(Evaluator &evaluator,
244
252
}
245
253
}
246
254
247
- if (NominalTypeDecl *nominal = ED->getExtendedNominal ()) {
248
- maxAccess = std::min (maxAccess,
249
- std::max (nominal->getFormalAccess (),
250
- AccessLevel::FilePrivate));
251
- }
252
-
253
255
AccessLevel defaultAccess;
254
256
if (auto *AA = ED->getAttrs ().getAttribute <AccessControlAttr>())
255
257
defaultAccess = std::max (AA->getAccess (), AccessLevel::FilePrivate);
0 commit comments