Skip to content

Commit 3fdf2ad

Browse files
committed
Add doc comments and rdars to tests
1 parent be20333 commit 3fdf2ad

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

include/swift/AST/AccessScope.h

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,13 @@ class AccessScope {
8585
return !Value.getPointer() && Value.getInt() == AccessLimitKind::Package;
8686
}
8787

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
9492
bool isChildOf(AccessScope AS) const {
95-
if (isInternalOrLess()) {
96-
if (AS.isInternalOrLess())
93+
if (isInContext()) {
94+
if (AS.isInContext())
9795
return allowsPrivateAccess(getDeclContext(), AS.getDeclContext());
9896
else
9997
return AS.isPackage() || AS.isPublic();
@@ -105,7 +103,27 @@ class AccessScope {
105103
return false;
106104
}
107105

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; }
109127

110128
/// Returns the associated access level for diagnostic purposes.
111129
AccessLevel accessLevelForDiagnostics() const;

test/Sema/accessibility.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,8 +1021,8 @@ public struct PublicWithInternalSettersConformPublic : PublicMutationOperations
10211021
}
10221022

10231023
public struct PublicWithPackageSettersConformPublic : PublicMutationOperations {
1024-
public package(set) var size = 0 // FIXME: this should error
1025-
public package(set) subscript (_: Int) -> Int { // FIXME: this should error
1024+
public package(set) var size = 0 // FIXME: rdar://104987295 this should error
1025+
public package(set) subscript (_: Int) -> Int { // FIXME: rdar://104987295 this should error
10261026
get { return 42 }
10271027
set {}
10281028
}
@@ -1471,7 +1471,7 @@ public class DerivedFromInternalConcreteGenericComposition : InternalConcreteGen
14711471
public func publicReq() {}
14721472
}
14731473

1474-
// FIXME: should have expected note and error 'class cannot be declared public because its superclass is internal'
1474+
// FIXME: rdar://104987455 should have expected note and error 'class cannot be declared public because its superclass is internal'
14751475
internal typealias InternalConcreteGenericCompositionPkg = PackageGenericClass<Int> & PackageProto
14761476
public class DerivedFromInternalConcreteGenericCompositionPkg : InternalConcreteGenericCompositionPkg { // expected-error {{class cannot be declared public because its superclass uses a package type as a generic parameter}}
14771477
public func packageReq() {}

0 commit comments

Comments
 (0)