@@ -85,15 +85,13 @@ class AccessScope {
85
85
return !Value.getPointer () && Value.getInt () == AccessLimitKind::Package;
86
86
}
87
87
88
- // / Returns true if this scope is more restrictive than the argument scope.
89
- // / This function does _not_ check if the access level is more restrictive than the argument access level.
90
- // / It checks if the scope of this use site is more restrictive than the scope of the argument (decl site).
91
- // / For example, the scope is FileUnit for a fileprivate decl, Module for an internal decl, and null for a public
92
- // / or package decl.
93
- // / \see DeclContext::isChildContextOf
88
+ // / Returns true if the context of this (use site) is more restrictive than
89
+ // / the argument context (decl site). This function does _not_ check the
90
+ // / restrictiveness of the access level between this and the argument. \see
91
+ // / AccessScope::isInContext
94
92
bool isChildOf (AccessScope AS) const {
95
- if (isInternalOrLess ()) {
96
- if (AS.isInternalOrLess ())
93
+ if (isInContext ()) {
94
+ if (AS.isInContext ())
97
95
return allowsPrivateAccess (getDeclContext (), AS.getDeclContext ());
98
96
else
99
97
return AS.isPackage () || AS.isPublic ();
@@ -105,7 +103,27 @@ class AccessScope {
105
103
return false ;
106
104
}
107
105
108
- bool isInternalOrLess () const { return getDeclContext () != nullptr ; }
106
+ // / Result depends on whether it's called at a use site or a decl site:
107
+ // /
108
+ // / For example,
109
+ // /
110
+ // / ```
111
+ // / public func foo(_ arg: bar) {} // `bar` is a `package` decl in another
112
+ // / module
113
+ // / ```
114
+ // /
115
+ // / The meaning of \c isInContext changes whether it's at the use site or the
116
+ // / decl site.
117
+ // /
118
+ // / The use site of \c bar, i.e. \c foo, is "in context" (decl context is
119
+ // / non-null), regardless of the access level of \c foo (\c public in this
120
+ // / case).
121
+ // /
122
+ // / The decl site of \c bar is only "in context" if the access level of the
123
+ // / decl is \c internal or more restrictive. The context at the decl site is\c
124
+ // / FileUnit if the decl is \c fileprivate or \c private; \c ModuleDecl if \c
125
+ // / internal, and null if \c package or \c public.
126
+ bool isInContext () const { return getDeclContext () != nullptr ; }
109
127
110
128
// / Returns the associated access level for diagnostic purposes.
111
129
AccessLevel accessLevelForDiagnostics () const ;
0 commit comments