@@ -3521,6 +3521,14 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
3521
3521
return storage->isSettable (storage->getDeclContext ());
3522
3522
};
3523
3523
3524
+ // We cannot use the same opened archetype in the getter and setter. Therefore
3525
+ // we create a new one for both the getter and the setter.
3526
+ auto renewOpenedArchetypes = [](SubstitutableType *type) -> Type {
3527
+ if (auto *openedTy = dyn_cast<OpenedArchetypeType>(type))
3528
+ return OpenedArchetypeType::get (openedTy->getOpenedExistentialType ());
3529
+ return type;
3530
+ };
3531
+
3524
3532
if (auto var = dyn_cast<VarDecl>(storage)) {
3525
3533
CanType componentTy;
3526
3534
if (!var->getDeclContext ()->isTypeContext ()) {
@@ -3544,13 +3552,15 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
3544
3552
auto id = getIdForKeyPathComponentComputedProperty (*this , var,
3545
3553
strategy);
3546
3554
auto getter = getOrCreateKeyPathGetter (*this , loc,
3547
- var, subs,
3555
+ var, subs.subst (renewOpenedArchetypes,
3556
+ MakeAbstractConformanceForGenericType ()),
3548
3557
needsGenericContext ? genericEnv : nullptr ,
3549
3558
expansion, {}, baseTy, componentTy);
3550
3559
3551
3560
if (isSettableInComponent ()) {
3552
3561
auto setter = getOrCreateKeyPathSetter (*this , loc,
3553
- var, subs,
3562
+ var, subs.subst (renewOpenedArchetypes,
3563
+ MakeAbstractConformanceForGenericType ()),
3554
3564
needsGenericContext ? genericEnv : nullptr ,
3555
3565
expansion, {}, baseTy, componentTy);
3556
3566
return KeyPathPatternComponent::forComputedSettableProperty (id,
@@ -3595,7 +3605,8 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
3595
3605
3596
3606
auto id = getIdForKeyPathComponentComputedProperty (*this , decl, strategy);
3597
3607
auto getter = getOrCreateKeyPathGetter (*this , loc,
3598
- decl, subs,
3608
+ decl, subs.subst (renewOpenedArchetypes,
3609
+ MakeAbstractConformanceForGenericType ()),
3599
3610
needsGenericContext ? genericEnv : nullptr ,
3600
3611
expansion,
3601
3612
indexTypes,
@@ -3604,7 +3615,8 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
3604
3615
auto indexPatternsCopy = getASTContext ().AllocateCopy (indexPatterns);
3605
3616
if (isSettableInComponent ()) {
3606
3617
auto setter = getOrCreateKeyPathSetter (*this , loc,
3607
- decl, subs,
3618
+ decl, subs.subst (renewOpenedArchetypes,
3619
+ MakeAbstractConformanceForGenericType ()),
3608
3620
needsGenericContext ? genericEnv : nullptr ,
3609
3621
expansion,
3610
3622
indexTypes,
0 commit comments