Skip to content

Commit e8a2a82

Browse files
authored
Merge pull request swiftlang#29193 from theblixguy/fix/SR-11994_5.2
[5.2] [PropertyWrappers] Fix a bug with class property wrapper access control
2 parents b48b420 + 8cc7a8a commit e8a2a82

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 9 additions & 3 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,7 +162,7 @@ findSuitableWrapperInit(ASTContext &ctx, NominalTypeDecl *nominal,
156162
}
157163

158164
// Check accessibility.
159-
if (init->getFormalAccess() < nominal->getFormalAccess()) {
165+
if (isDeclNotAsAccessibleAsParent(init, nominal)) {
160166
nonviable.push_back(
161167
std::make_tuple(init, NonViableReason::Inaccessible, Type()));
162168
continue;
@@ -272,7 +278,7 @@ static SubscriptDecl *findEnclosingSelfSubscript(ASTContext &ctx,
272278

273279
auto subscript = subscripts.front();
274280
// the subscript must be as accessible as the nominal type.
275-
if (subscript->getFormalAccess() < nominal->getFormalAccess()) {
281+
if (isDeclNotAsAccessibleAsParent(subscript, nominal)) {
276282
subscript->diagnose(diag::property_wrapper_type_requirement_not_accessible,
277283
subscript->getFormalAccess(),
278284
subscript->getDescriptiveKind(),

test/decl/var/property_wrappers.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,3 +1870,13 @@ struct Rdar57411331 {
18701870

18711871
var other: Int
18721872
}
1873+
1874+
// SR-11994
1875+
@propertyWrapper
1876+
open class OpenPropertyWrapperWithPublicInit {
1877+
public init(wrappedValue: String) { // Okay
1878+
self.wrappedValue = wrappedValue
1879+
}
1880+
1881+
open var wrappedValue: String = "Hello, world"
1882+
}

0 commit comments

Comments
 (0)