Skip to content

Commit 9b95242

Browse files
authored
[cxx-interop] Import const-qualified indirect fields with private setters (#83219)
We already make imported computed properties' setters private in VisitFieldDecl(), but not in VisitIndirectFieldDecl(), which handles things like the members of an anonymous union in another struct.
1 parent a5e6b85 commit 9b95242

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3371,6 +3371,12 @@ namespace {
33713371
result->setInterfaceType(type);
33723372
result->setIsObjC(false);
33733373
result->setIsDynamic(false);
3374+
if (decl->getType().isConstQualified()) {
3375+
// Note that in C++ there are ways to change the values of const
3376+
// members, so we don't use WriteImplKind::Immutable storage.
3377+
assert(result->supportsMutation());
3378+
result->overwriteSetterAccess(AccessLevel::Private);
3379+
}
33743380
Impl.recordImplicitUnwrapForDecl(result,
33753381
importedType.isImplicitlyUnwrapped());
33763382

test/Interop/Cxx/union/anonymous-union-const-member.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ func fooer(_ f: inout Foo) {
2828
let _ = f.variable
2929
let _ = f.constant
3030
f.variable = 42
31-
// f.constant = 42 // FIXME: this should not work (but currently does)
31+
f.constant = 42 // expected-error {{setter is inaccessible}}
3232
}

0 commit comments

Comments
 (0)