@@ -36,6 +36,12 @@ enum class PropertyWrapperInitKind {
36
36
Default
37
37
};
38
38
39
+ static bool isDeclNotAsAccessibleAsParent (ValueDecl *decl,
40
+ NominalTypeDecl *parent) {
41
+ return decl->getFormalAccess () <
42
+ std::min (parent->getFormalAccess (), AccessLevel::Public);
43
+ }
44
+
39
45
// / Find the named property in a property wrapper to which access will
40
46
// / be delegated.
41
47
static VarDecl *findValueProperty (ASTContext &ctx, NominalTypeDecl *nominal,
@@ -78,7 +84,7 @@ static VarDecl *findValueProperty(ASTContext &ctx, NominalTypeDecl *nominal,
78
84
79
85
// The property must be as accessible as the nominal type.
80
86
VarDecl *var = vars.front ();
81
- if (var-> getFormalAccess () < nominal-> getFormalAccess ( )) {
87
+ if (isDeclNotAsAccessibleAsParent (var, nominal)) {
82
88
var->diagnose (diag::property_wrapper_type_requirement_not_accessible,
83
89
var->getFormalAccess (), var->getDescriptiveKind (),
84
90
var->getFullName (), nominal->getDeclaredType (),
@@ -156,7 +162,7 @@ findSuitableWrapperInit(ASTContext &ctx, NominalTypeDecl *nominal,
156
162
}
157
163
158
164
// Check accessibility.
159
- if (init-> getFormalAccess () < nominal-> getFormalAccess ( )) {
165
+ if (isDeclNotAsAccessibleAsParent (init, nominal)) {
160
166
nonviable.push_back (
161
167
std::make_tuple (init, NonViableReason::Inaccessible, Type ()));
162
168
continue ;
@@ -272,7 +278,7 @@ static SubscriptDecl *findEnclosingSelfSubscript(ASTContext &ctx,
272
278
273
279
auto subscript = subscripts.front ();
274
280
// the subscript must be as accessible as the nominal type.
275
- if (subscript-> getFormalAccess () < nominal-> getFormalAccess ( )) {
281
+ if (isDeclNotAsAccessibleAsParent (subscript, nominal)) {
276
282
subscript->diagnose (diag::property_wrapper_type_requirement_not_accessible,
277
283
subscript->getFormalAccess (),
278
284
subscript->getDescriptiveKind (),
0 commit comments