@@ -655,19 +655,29 @@ namespace {
655
655
return visitAbstractTypeParamType (type, origType, isSensitive);
656
656
}
657
657
658
- Type getConcreteReferenceStorageReferent (Type type ,
658
+ Type getConcreteReferenceStorageReferent (Type substType ,
659
659
AbstractionPattern origType) {
660
- if (type->isTypeParameter ()) {
661
- auto genericSig = origType.getGenericSignature ();
662
- if (auto concreteType = genericSig->getConcreteType (type))
663
- return concreteType;
664
- if (auto superclassType = genericSig->getSuperclassBound (type))
665
- return superclassType;
666
- assert (genericSig->requiresClass (type));
660
+ substType = substType->getReferenceStorageReferent ();
661
+ origType = origType.getReferenceStorageReferentType ();
662
+
663
+ if (auto objectType = substType->getOptionalObjectType ()) {
664
+ substType = objectType;
665
+ origType = origType.getOptionalObjectType ();
666
+ }
667
+
668
+ if (substType->isTypeParameter ()) {
669
+ if (auto genericSig = origType.getGenericSignature ()) {
670
+ auto type = origType.getType ();
671
+ if (auto concreteType = genericSig->getConcreteType (type))
672
+ return concreteType;
673
+ if (auto superclassType = genericSig->getSuperclassBound (type))
674
+ return superclassType;
675
+ assert (genericSig->requiresClass (type));
676
+ }
667
677
return TC.Context .getAnyObjectType ();
668
678
}
669
679
670
- return type ;
680
+ return substType ;
671
681
}
672
682
673
683
#define NEVER_LOADABLE_CHECKED_REF_STORAGE (Name, ...) \
@@ -710,9 +720,7 @@ namespace {
710
720
RetTy visit##Name##StorageType(Can##Name##StorageType type, \
711
721
AbstractionPattern origType, \
712
722
IsTypeExpansionSensitive_t isSensitive) { \
713
- auto referentType = \
714
- type->getReferentType ()->lookThroughSingleOptionalType (); \
715
- auto concreteType = getConcreteReferenceStorageReferent (referentType, origType); \
723
+ auto concreteType = getConcreteReferenceStorageReferent (type, origType); \
716
724
if (Name##StorageType::get (concreteType, TC.Context ) \
717
725
->isLoadable (Expansion.getResilienceExpansion ())) { \
718
726
return asImpl ().visitLoadable ##Name##StorageType (type, origType, \
0 commit comments