@@ -2824,6 +2824,13 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
2824
2824
auto access = getAccessLevel ();
2825
2825
auto *sourceDC = VD->getDeclContext ();
2826
2826
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
+
2827
2834
if (!forConformance) {
2828
2835
if (auto *proto = sourceDC->getSelfProtocolDecl ()) {
2829
2836
// FIXME: Swift 4.1 allowed accessing protocol extension methods that were
@@ -2878,21 +2885,8 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
2878
2885
2879
2886
bool ValueDecl::isAccessibleFrom (const DeclContext *useDC,
2880
2887
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 (); });
2896
2890
}
2897
2891
2898
2892
bool AbstractStorageDecl::isSetterAccessibleFrom (const DeclContext *DC,
0 commit comments