Skip to content

Commit 8cc7a8a

Browse files
committed
[PropertyWrappers] Extract the access control check into a separate static method
1 parent 79fc782 commit 8cc7a8a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ enum class PropertyWrapperInitKind {
3636
Default
3737
};
3838

39+
static bool isDeclNotAsAccessibleAsParent(ValueDecl *decl,
40+
NominalTypeDecl *parent) {
41+
return decl->getFormalAccess() <
42+
std::min(parent->getFormalAccess(), AccessLevel::Public);
43+
}
44+
3945
/// Find the named property in a property wrapper to which access will
4046
/// be delegated.
4147
static VarDecl *findValueProperty(ASTContext &ctx, NominalTypeDecl *nominal,
@@ -78,7 +84,7 @@ static VarDecl *findValueProperty(ASTContext &ctx, NominalTypeDecl *nominal,
7884

7985
// The property must be as accessible as the nominal type.
8086
VarDecl *var = vars.front();
81-
if (var->getFormalAccess() < nominal->getFormalAccess()) {
87+
if (isDeclNotAsAccessibleAsParent(var, nominal)) {
8288
var->diagnose(diag::property_wrapper_type_requirement_not_accessible,
8389
var->getFormalAccess(), var->getDescriptiveKind(),
8490
var->getFullName(), nominal->getDeclaredType(),
@@ -156,8 +162,7 @@ findSuitableWrapperInit(ASTContext &ctx, NominalTypeDecl *nominal,
156162
}
157163

158164
// Check accessibility.
159-
if (init->getFormalAccess() <
160-
std::min(nominal->getFormalAccess(), AccessLevel::Public)) {
165+
if (isDeclNotAsAccessibleAsParent(init, nominal)) {
161166
nonviable.push_back(
162167
std::make_tuple(init, NonViableReason::Inaccessible, Type()));
163168
continue;
@@ -273,7 +278,7 @@ static SubscriptDecl *findEnclosingSelfSubscript(ASTContext &ctx,
273278

274279
auto subscript = subscripts.front();
275280
// the subscript must be as accessible as the nominal type.
276-
if (subscript->getFormalAccess() < nominal->getFormalAccess()) {
281+
if (isDeclNotAsAccessibleAsParent(subscript, nominal)) {
277282
subscript->diagnose(diag::property_wrapper_type_requirement_not_accessible,
278283
subscript->getFormalAccess(),
279284
subscript->getDescriptiveKind(),

0 commit comments

Comments
 (0)