Skip to content

Commit 3c47a58

Browse files
committed
[SILGen] Amend checks preventing metatype keypaths in SilGen.
1 parent ffb8baf commit 3c47a58

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,9 +1873,10 @@ SILGenModule::canStorageUseStoredKeyPathComponent(AbstractStorageDecl *decl,
18731873
expansion);
18741874
switch (strategy.getKind()) {
18751875
case AccessStrategy::Storage: {
1876-
// Keypaths rely on accessors to handle the special behavior of weak or
1877-
// unowned properties.
1878-
if (decl->getInterfaceType()->is<ReferenceStorageType>())
1876+
// Keypaths rely on accessors to handle the special behavior of weak,
1877+
// unowned, or static properties.
1878+
if (decl->getInterfaceType()->is<ReferenceStorageType>() ||
1879+
decl->isStatic())
18791880
return false;
18801881

18811882
// If the field offset depends on the generic instantiation, we have to
@@ -1973,10 +1974,7 @@ void SILGenModule::tryEmitPropertyDescriptor(AbstractStorageDecl *decl) {
19731974

19741975
Type baseTy;
19751976
if (decl->getDeclContext()->isTypeContext()) {
1976-
// TODO: Static properties should eventually be referenceable as
1977-
// keypaths from T.Type -> Element, viz `baseTy = MetatypeType::get(baseTy)`
1978-
assert(!decl->isStatic());
1979-
1977+
19801978
baseTy = decl->getDeclContext()->getSelfInterfaceType()
19811979
->getReducedType(decl->getInnermostDeclContext()
19821980
->getGenericSignatureOfContext());

lib/SILGen/SILGenExpr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3174,6 +3174,11 @@ emitKeyPathRValueBase(SILGenFunction &subSGF,
31743174
auto paramSubstValue = subSGF.emitOrigToSubstValue(loc, paramOrigValue,
31753175
AbstractionPattern::getOpaque(),
31763176
baseType);
3177+
3178+
// If base is a metatype, it cannot be opened as an existential or upcasted
3179+
// from a class.
3180+
if (baseType->is<MetatypeType>())
3181+
return paramSubstValue;
31773182

31783183
// Pop open an existential container base.
31793184
if (baseType->isAnyExistentialType()) {

0 commit comments

Comments
 (0)