@@ -85,13 +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
- // / It's often used to compute the min access scope. The order of restrictiveness
90
- // / is: private (most restrictive), fileprivate, internal, package, public (least restrictive).
91
- // / \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
92
92
bool isChildOf (AccessScope AS) const {
93
- if (isInternalOrLess ()) {
94
- if (AS.isInternalOrLess ())
93
+ if (isInContext ()) {
94
+ if (AS.isInContext ())
95
95
return allowsPrivateAccess (getDeclContext (), AS.getDeclContext ());
96
96
else
97
97
return AS.isPackage () || AS.isPublic ();
@@ -103,7 +103,27 @@ class AccessScope {
103
103
return false ;
104
104
}
105
105
106
- 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 ; }
107
127
108
128
// / Returns the associated access level for diagnostic purposes.
109
129
AccessLevel accessLevelForDiagnostics () const ;
0 commit comments