Skip to content

Commit fc9035a

Browse files
committed
[SILGen] Amend checks preventing metatype keypaths in SilGen.
1 parent 63b02ff commit fc9035a

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
@@ -1856,9 +1856,10 @@ SILGenModule::canStorageUseStoredKeyPathComponent(AbstractStorageDecl *decl,
18561856
expansion);
18571857
switch (strategy.getKind()) {
18581858
case AccessStrategy::Storage: {
1859-
// Keypaths rely on accessors to handle the special behavior of weak or
1860-
// unowned properties.
1861-
if (decl->getInterfaceType()->is<ReferenceStorageType>())
1859+
// Keypaths rely on accessors to handle the special behavior of weak,
1860+
// unowned, or static properties.
1861+
if (decl->getInterfaceType()->is<ReferenceStorageType>() ||
1862+
decl->isStatic())
18621863
return false;
18631864

18641865
// If the field offset depends on the generic instantiation, we have to
@@ -1956,10 +1957,7 @@ void SILGenModule::tryEmitPropertyDescriptor(AbstractStorageDecl *decl) {
19561957

19571958
Type baseTy;
19581959
if (decl->getDeclContext()->isTypeContext()) {
1959-
// TODO: Static properties should eventually be referenceable as
1960-
// keypaths from T.Type -> Element, viz `baseTy = MetatypeType::get(baseTy)`
1961-
assert(!decl->isStatic());
1962-
1960+
19631961
baseTy = decl->getDeclContext()->getSelfInterfaceType()
19641962
->getReducedType(decl->getInnermostDeclContext()
19651963
->getGenericSignatureOfContext());

lib/SILGen/SILGenExpr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3164,6 +3164,11 @@ emitKeyPathRValueBase(SILGenFunction &subSGF,
31643164
auto paramSubstValue = subSGF.emitOrigToSubstValue(loc, paramOrigValue,
31653165
AbstractionPattern::getOpaque(),
31663166
baseType);
3167+
3168+
// If base is a metatype, it cannot be opened as an existential or upcasted
3169+
// from a class.
3170+
if (baseType->is<MetatypeType>())
3171+
return paramSubstValue;
31673172

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

0 commit comments

Comments
 (0)