@@ -136,16 +136,7 @@ class StoredPropertyProjector : public ComponentProjector {
136
136
while (Ref->getType ().getClassOrBoundGenericClass () !=
137
137
storedProperty->getDeclContext ()) {
138
138
SILType superCl = Ref->getType ().getSuperclass ();
139
- if (!superCl) {
140
- // This should never happen, because the property should be in the
141
- // decl or in a superclass of it. Just handle this to be on the safe
142
- // side.
143
- callback (SILValue ());
144
- if (Borrow) {
145
- builder.createEndBorrow (loc, Borrow);
146
- }
147
- return ;
148
- }
139
+ ASSERT (superCl && " the property should be in the decl or in a superclass of it" );
149
140
Ref = builder.createUpcast (loc, Ref, superCl);
150
141
}
151
142
@@ -701,15 +692,28 @@ KeyPathProjector::create(SILValue keyPath, SILValue root,
701
692
// Check if the keypath only contains patterns which we support.
702
693
auto components = kpInst->getPattern ()->getComponents ();
703
694
for (const KeyPathPatternComponent &comp : components) {
704
- if (comp.getKind () == KeyPathPatternComponent::Kind::GettableProperty ||
705
- comp.getKind () == KeyPathPatternComponent::Kind::SettableProperty) {
706
- if (!comp.getExternalSubstitutions ().empty () ||
707
- !comp.getSubscriptIndices ().empty ()) {
708
- // TODO: right now we can't optimize computed properties that require
709
- // additional context for subscript indices or generic environment
710
- // See https://github.com/apple/swift/pull/28799#issuecomment-570299845
711
- return nullptr ;
695
+ switch (comp.getKind ()) {
696
+ case KeyPathPatternComponent::Kind::GettableProperty:
697
+ case KeyPathPatternComponent::Kind::SettableProperty:
698
+ if (!comp.getExternalSubstitutions ().empty () ||
699
+ !comp.getSubscriptIndices ().empty ()) {
700
+ // TODO: right now we can't optimize computed properties that require
701
+ // additional context for subscript indices or generic environment
702
+ // See https://github.com/apple/swift/pull/28799#issuecomment-570299845
703
+ return nullptr ;
704
+ }
705
+ break ;
706
+ case KeyPathPatternComponent::Kind::StoredProperty: {
707
+ auto *declCtxt = comp.getStoredPropertyDecl ()->getDeclContext ();
708
+ if (!isa<StructDecl>(declCtxt) && !isa<ClassDecl>(declCtxt)) {
709
+ // This can happen, e.g. for ObjectiveC class properties, which are
710
+ // defined in an extension.
711
+ return nullptr ;
712
+ }
713
+ break ;
712
714
}
715
+ default :
716
+ break ;
713
717
}
714
718
}
715
719
0 commit comments