@@ -947,29 +947,6 @@ IterableDeclContext::castDeclToIterableDeclContext(const Decl *D) {
947
947
llvm_unreachable (" Unhandled DeclKind in switch." );
948
948
}
949
949
950
- AccessScope::AccessScope (const DeclContext *DC, bool isPrivate)
951
- : Value(DC, isPrivate) {
952
- if (!DC || isa<ModuleDecl>(DC))
953
- assert (!isPrivate && " public or internal scope can't be private" );
954
- }
955
-
956
- bool AccessScope::isFileScope () const {
957
- auto DC = getDeclContext ();
958
- return DC && isa<FileUnit>(DC);
959
- }
960
-
961
- Accessibility AccessScope::accessibilityForDiagnostics () const {
962
- if (isPublic ())
963
- return Accessibility::Public;
964
- if (isa<ModuleDecl>(getDeclContext ()))
965
- return Accessibility::Internal;
966
- if (getDeclContext ()->isModuleScopeContext ()) {
967
- return isPrivate () ? Accessibility::Private : Accessibility::FilePrivate;
968
- }
969
-
970
- return Accessibility::Private;
971
- }
972
-
973
950
// / Return the DeclContext to compare when checking private access in
974
951
// / Swift 4 mode. The context returned is the type declaration if the context
975
952
// / and the type declaration are in the same file, otherwise it is the types
@@ -996,6 +973,33 @@ getPrivateDeclContext(const DeclContext *DC, const SourceFile *useSF) {
996
973
return lastExtension ? lastExtension : DC;
997
974
}
998
975
976
+ AccessScope::AccessScope (const DeclContext *DC, bool isPrivate)
977
+ : Value(DC, isPrivate) {
978
+ if (isPrivate) {
979
+ DC = getPrivateDeclContext (DC, DC->getParentSourceFile ());
980
+ Value.setPointer (DC);
981
+ }
982
+ if (!DC || isa<ModuleDecl>(DC))
983
+ assert (!isPrivate && " public or internal scope can't be private" );
984
+ }
985
+
986
+ bool AccessScope::isFileScope () const {
987
+ auto DC = getDeclContext ();
988
+ return DC && isa<FileUnit>(DC);
989
+ }
990
+
991
+ Accessibility AccessScope::accessibilityForDiagnostics () const {
992
+ if (isPublic ())
993
+ return Accessibility::Public;
994
+ if (isa<ModuleDecl>(getDeclContext ()))
995
+ return Accessibility::Internal;
996
+ if (getDeclContext ()->isModuleScopeContext ()) {
997
+ return isPrivate () ? Accessibility::Private : Accessibility::FilePrivate;
998
+ }
999
+
1000
+ return Accessibility::Private;
1001
+ }
1002
+
999
1003
bool AccessScope::allowsPrivateAccess (const DeclContext *useDC, const DeclContext *sourceDC) {
1000
1004
// Check the lexical scope.
1001
1005
if (useDC->isChildContextOf (sourceDC))
@@ -1005,11 +1009,14 @@ bool AccessScope::allowsPrivateAccess(const DeclContext *useDC, const DeclContex
1005
1009
if (useDC->getASTContext ().isSwiftVersion3 ())
1006
1010
return false ;
1007
1011
1008
- // Do not allow access if the sourceDC is in a different file, or if the
1009
- // sourceDC does not represent a type.
1010
- auto sourceNTD = sourceDC->getAsNominalTypeOrNominalTypeExtensionContext ();
1012
+ // Do not allow access if the sourceDC is in a different file
1011
1013
auto useSF = useDC->getParentSourceFile ();
1012
- if (useSF != sourceDC->getParentSourceFile () || !sourceNTD)
1014
+ if (useSF != sourceDC->getParentSourceFile ())
1015
+ return false ;
1016
+
1017
+ // Do not allow access if the sourceDC does not represent a type.
1018
+ auto sourceNTD = sourceDC->getAsNominalTypeOrNominalTypeExtensionContext ();
1019
+ if (!sourceNTD)
1013
1020
return false ;
1014
1021
1015
1022
// Compare the private scopes and iterate over the parent types.
0 commit comments