Skip to content

Commit 18e4199

Browse files
authored
Merge pull request #35454 from CodaFi/checkride
2 parents af53073 + eba9bbe commit 18e4199

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

lib/AST/AccessRequests.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,21 @@ DefaultAndMaxAccessLevelRequest::evaluate(Evaluator &evaluator,
221221

222222
Optional<AccessScope> maxScope = AccessScope::getPublic();
223223

224+
// Try to scope the extension's access to the least public type mentioned
225+
// in its where clause.
224226
for (auto *typeDecl : typeDecls) {
225227
if (isa<TypeAliasDecl>(typeDecl) || isa<NominalTypeDecl>(typeDecl)) {
226228
auto scope = typeDecl->getFormalAccessScope(ED->getDeclContext());
227229
maxScope = maxScope->intersectWith(scope);
228230
}
229231
}
230232

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+
231239
if (!maxScope.hasValue()) {
232240
// This is an error case and will be diagnosed elsewhere.
233241
maxAccess = AccessLevel::Public;
@@ -244,12 +252,6 @@ DefaultAndMaxAccessLevelRequest::evaluate(Evaluator &evaluator,
244252
}
245253
}
246254

247-
if (NominalTypeDecl *nominal = ED->getExtendedNominal()) {
248-
maxAccess = std::min(maxAccess,
249-
std::max(nominal->getFormalAccess(),
250-
AccessLevel::FilePrivate));
251-
}
252-
253255
AccessLevel defaultAccess;
254256
if (auto *AA = ED->getAttrs().getAttribute<AccessControlAttr>())
255257
defaultAccess = std::max(AA->getAccess(), AccessLevel::FilePrivate);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
struct Catch22<Value>: Equatable where Value: Equatable {
2+
var value: Value
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module-path %t/catch22.swiftmodule %S/Inputs/conditional-conformance-catch22.swift -module-name catch22 -enable-testing
3+
// RUN: %target-swift-frontend -typecheck %s -I %t
4+
5+
@testable import catch22
6+
7+
extension Catch22: Comparable where Value: Comparable {
8+
public static func <(lhs: Catch22, rhs: Catch22) -> Bool { true }
9+
}

0 commit comments

Comments
 (0)