Skip to content

Commit a06fe96

Browse files
committed
[SILGen] fix key path setter access for @testable
emitKeyPathComponentForDecl was only checking if the setter was accessible from the current module, not the current function. This failed when accessing an internal setter from a module imported for testing.
1 parent d7acf12 commit a06fe96

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,7 @@ void SILGenModule::tryEmitPropertyDescriptor(AbstractStorageDecl *decl) {
14581458
baseOperand, needsGenericContext,
14591459
subs, decl, {},
14601460
baseTy->getCanonicalType(),
1461+
M.getSwiftModule(),
14611462
/*property descriptor*/ true);
14621463

14631464
(void)SILProperty::create(M, /*serialized*/ false, decl, component);

lib/SILGen/SILGen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
342342
AbstractStorageDecl *storage,
343343
ArrayRef<ProtocolConformanceRef> indexHashables,
344344
CanType baseTy,
345+
DeclContext *useDC,
345346
bool forPropertyDescriptor);
346347

347348
/// Known functions for bridging.

lib/SILGen/SILGenExpr.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,6 +3354,7 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
33543354
AbstractStorageDecl *storage,
33553355
ArrayRef<ProtocolConformanceRef> indexHashables,
33563356
CanType baseTy,
3357+
DeclContext *useDC,
33573358
bool forPropertyDescriptor) {
33583359
auto baseDecl = storage;
33593360

@@ -3423,8 +3424,8 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
34233424
// supply the settability if needed. We only reference it here if the
34243425
// setter is public.
34253426
if (shouldUseExternalKeyPathComponent())
3426-
return storage->isSettable(M.getSwiftModule())
3427-
&& storage->isSetterAccessibleFrom(M.getSwiftModule());
3427+
return storage->isSettable(useDC)
3428+
&& storage->isSetterAccessibleFrom(useDC);
34283429
return storage->isSettable(storage->getDeclContext());
34293430
};
34303431

@@ -3578,6 +3579,7 @@ RValue RValueEmitter::visitKeyPathExpr(KeyPathExpr *E, SGFContext C) {
35783579
decl,
35793580
component.getSubscriptIndexHashableConformances(),
35803581
baseTy,
3582+
SGF.FunctionDC,
35813583
/*for descriptor*/ false));
35823584
baseTy = loweredComponents.back().getComponentType();
35833585
if (kind == KeyPathExpr::Component::Kind::Property)

0 commit comments

Comments
 (0)