@@ -2781,10 +2781,12 @@ static bool checkAccessUsingAccessScopes(const DeclContext *useDC,
27812781// /
27822782// / See ValueDecl::isAccessibleFrom for a description of \p forConformance.
27832783static bool checkAccess (const DeclContext *useDC, const ValueDecl *VD,
2784- AccessLevel access, bool forConformance) {
2784+ bool forConformance,
2785+ llvm::function_ref<AccessLevel()> getAccessLevel) {
27852786 if (VD->getASTContext ().isAccessControlDisabled ())
27862787 return true ;
27872788
2789+ auto access = getAccessLevel ();
27882790 auto *sourceDC = VD->getDeclContext ();
27892791
27902792 if (!forConformance) {
@@ -2846,8 +2848,8 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
28462848
28472849bool ValueDecl::isAccessibleFrom (const DeclContext *useDC,
28482850 bool forConformance) const {
2849- auto access = getFormalAccess ();
2850- bool result = checkAccess (useDC, this , access, forConformance );
2851+ bool result = checkAccess (useDC, this , forConformance,
2852+ [&]() { return getFormalAccess (); } );
28512853
28522854 // For everything outside of protocols and operators, we should get the same
28532855 // result using either implementation of checkAccess, because useDC must
@@ -2856,9 +2858,9 @@ bool ValueDecl::isAccessibleFrom(const DeclContext *useDC,
28562858 // because we're finding internal operators within private types. Fortunately
28572859 // we have a requirement that a member operator take the enclosing type as an
28582860 // argument, so it won't ever match.
2859- assert (getDeclContext ()->getSelfProtocolDecl () ||
2860- isOperator () ||
2861- result == checkAccessUsingAccessScopes (useDC, this , access ));
2861+ assert (getDeclContext ()->getSelfProtocolDecl () || isOperator () ||
2862+ result ==
2863+ checkAccessUsingAccessScopes (useDC, this , getFormalAccess () ));
28622864
28632865 return result;
28642866}
@@ -2876,8 +2878,8 @@ bool AbstractStorageDecl::isSetterAccessibleFrom(const DeclContext *DC,
28762878 if (isa<ParamDecl>(this ))
28772879 return true ;
28782880
2879- auto access = getSetterFormalAccess ();
2880- return checkAccess (DC, this , access, forConformance );
2881+ return checkAccess (DC, this , forConformance,
2882+ [&]() { return getSetterFormalAccess (); } );
28812883}
28822884
28832885void ValueDecl::copyFormalAccessFrom (const ValueDecl *source,
0 commit comments