Skip to content

Commit 4e77005

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 d9976bd commit 4e77005

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
@@ -1460,6 +1460,7 @@ void SILGenModule::tryEmitPropertyDescriptor(AbstractStorageDecl *decl) {
14601460
baseOperand, needsGenericContext,
14611461
subs, decl, {},
14621462
baseTy->getCanonicalType(),
1463+
M.getSwiftModule(),
14631464
/*property descriptor*/ true);
14641465

14651466
(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
@@ -339,6 +339,7 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
339339
AbstractStorageDecl *storage,
340340
ArrayRef<ProtocolConformanceRef> indexHashables,
341341
CanType baseTy,
342+
DeclContext *useDC,
342343
bool forPropertyDescriptor);
343344

344345
/// Known functions for bridging.

lib/SILGen/SILGenExpr.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3401,6 +3401,7 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
34013401
AbstractStorageDecl *storage,
34023402
ArrayRef<ProtocolConformanceRef> indexHashables,
34033403
CanType baseTy,
3404+
DeclContext *useDC,
34043405
bool forPropertyDescriptor) {
34053406
auto baseDecl = storage;
34063407

@@ -3470,8 +3471,8 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
34703471
// supply the settability if needed. We only reference it here if the
34713472
// setter is public.
34723473
if (shouldUseExternalKeyPathComponent())
3473-
return storage->isSettable(M.getSwiftModule())
3474-
&& storage->isSetterAccessibleFrom(M.getSwiftModule());
3474+
return storage->isSettable(useDC)
3475+
&& storage->isSetterAccessibleFrom(useDC);
34753476
return storage->isSettable(storage->getDeclContext());
34763477
};
34773478

@@ -3625,6 +3626,7 @@ RValue RValueEmitter::visitKeyPathExpr(KeyPathExpr *E, SGFContext C) {
36253626
decl,
36263627
component.getSubscriptIndexHashableConformances(),
36273628
baseTy,
3629+
SGF.FunctionDC,
36283630
/*for descriptor*/ false));
36293631
baseTy = loweredComponents.back().getComponentType();
36303632
if (kind == KeyPathExpr::Component::Kind::Property)

0 commit comments

Comments
 (0)