@@ -970,13 +970,13 @@ Accessibility AccessScope::accessibilityForDiagnostics() const {
970
970
return Accessibility::Private;
971
971
}
972
972
973
- // / Return the DeclContext to compare when checking shared private access in
974
- // / Swift 4 mode. The shared scope is the type declaration if the context
973
+ // / Return the DeclContext to compare when checking private access in
974
+ // / Swift 4 mode. The context returned is the type declaration if the context
975
975
// / and the type declaration are in the same file, otherwise it is the types
976
976
// / last extension in the source file. If the context does not refer to a
977
977
// / declaration or extension, the supplied context is returned.
978
978
static const DeclContext *
979
- getSharedPrivateDeclContext (const DeclContext *DC, const SourceFile *useSF) {
979
+ getPrivateDeclContext (const DeclContext *DC, const SourceFile *useSF) {
980
980
auto NTD = DC->getAsNominalTypeOrNominalTypeExtensionContext ();
981
981
if (!NTD)
982
982
return DC;
@@ -996,8 +996,12 @@ getSharedPrivateDeclContext(const DeclContext *DC, const SourceFile *useSF) {
996
996
return lastExtension ? lastExtension : DC;
997
997
}
998
998
999
- bool AccessScope::checkSharedPrivateAccess (const DeclContext *useDC, const DeclContext *sourceDC) {
1000
- // Shared private scope is not performed in Swift 3 mode.
999
+ bool AccessScope::allowsPrivateAccess (const DeclContext *useDC, const DeclContext *sourceDC) {
1000
+ // Check the lexical scope.
1001
+ if (useDC->isChildContextOf (sourceDC))
1002
+ return true ;
1003
+
1004
+ // Only check lexical scope in Swift 3 mode
1001
1005
if (useDC->getASTContext ().isSwiftVersion3 ())
1002
1006
return false ;
1003
1007
@@ -1008,10 +1012,10 @@ bool AccessScope::checkSharedPrivateAccess(const DeclContext *useDC, const DeclC
1008
1012
if (useSF != sourceDC->getParentSourceFile () || !sourceNTD)
1009
1013
return false ;
1010
1014
1011
- // Compare the shared private scopes and iterate over the parent types.
1012
- sourceDC = getSharedPrivateDeclContext (sourceDC, useSF);
1015
+ // Compare the private scopes and iterate over the parent types.
1016
+ sourceDC = getPrivateDeclContext (sourceDC, useSF);
1013
1017
while (!useDC->isModuleContext ()) {
1014
- useDC = getSharedPrivateDeclContext (useDC, useSF);
1018
+ useDC = getPrivateDeclContext (useDC, useSF);
1015
1019
if (useDC == sourceDC)
1016
1020
return true ;
1017
1021
0 commit comments