Skip to content

Commit 73d174d

Browse files
authored
Merge pull request #23341 from xedin/allow-access-check-into-inaccesible-members
[AST] Allow access-scope based access check inside inaccessible members
2 parents 6eed1f9 + d8d5190 commit 73d174d

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

lib/AST/Decl.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,6 +2824,13 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
28242824
auto access = getAccessLevel();
28252825
auto *sourceDC = VD->getDeclContext();
28262826

2827+
// Preserve "fast path" behavior for everything inside
2828+
// protocol extensions and operators, otherwise allow access
2829+
// check declarations inside inaccessible members via slower
2830+
// access scope based check, which is helpful for diagnostics.
2831+
if (!(sourceDC->getSelfProtocolDecl() || VD->isOperator()))
2832+
return checkAccessUsingAccessScopes(useDC, VD, access);
2833+
28272834
if (!forConformance) {
28282835
if (auto *proto = sourceDC->getSelfProtocolDecl()) {
28292836
// FIXME: Swift 4.1 allowed accessing protocol extension methods that were
@@ -2878,21 +2885,8 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
28782885

28792886
bool ValueDecl::isAccessibleFrom(const DeclContext *useDC,
28802887
bool forConformance) const {
2881-
bool result = checkAccess(useDC, this, forConformance,
2882-
[&]() { return getFormalAccess(); });
2883-
2884-
// For everything outside of protocols and operators, we should get the same
2885-
// result using either implementation of checkAccess, because useDC must
2886-
// already have access to this declaration's DeclContext.
2887-
// FIXME: Arguably, we're doing the wrong thing for operators here too,
2888-
// because we're finding internal operators within private types. Fortunately
2889-
// we have a requirement that a member operator take the enclosing type as an
2890-
// argument, so it won't ever match.
2891-
assert(getDeclContext()->getSelfProtocolDecl() || isOperator() ||
2892-
result ==
2893-
checkAccessUsingAccessScopes(useDC, this, getFormalAccess()));
2894-
2895-
return result;
2888+
return checkAccess(useDC, this, forConformance,
2889+
[&]() { return getFormalAccess(); });
28962890
}
28972891

28982892
bool AbstractStorageDecl::isSetterAccessibleFrom(const DeclContext *DC,

0 commit comments

Comments
 (0)