@@ -3181,15 +3181,12 @@ operator()(SubstitutableType *maybeOpaqueType) const {
3181
3181
// archetype in question. This will map the inner generic signature of the
3182
3182
// opaque type to its outer signature.
3183
3183
auto partialSubstTy = archetype->getInterfaceType ().subst (*subs);
3184
- // Then apply the substitutions from the root opaque archetype, to specialize
3185
- // for its type arguments.
3186
- auto substTy = partialSubstTy.subst (opaqueRoot->getSubstitutions ());
3187
3184
3188
3185
// Check that we are allowed to substitute the underlying type into the
3189
3186
// context.
3190
3187
auto inContext = this ->inContext ;
3191
3188
auto isContextWholeModule = this ->isContextWholeModule ;
3192
- if (substTy .findIf (
3189
+ if (partialSubstTy .findIf (
3193
3190
[inContext, substitutionKind, isContextWholeModule](Type t) -> bool {
3194
3191
if (!canSubstituteTypeInto (t, inContext, substitutionKind,
3195
3192
isContextWholeModule))
@@ -3198,6 +3195,12 @@ operator()(SubstitutableType *maybeOpaqueType) const {
3198
3195
}))
3199
3196
return maybeOpaqueType;
3200
3197
3198
+ // Then apply the substitutions from the root opaque archetype, to specialize
3199
+ // for its type arguments. We perform this substitution after checking for
3200
+ // visibility, since we do not want the result of the visibility check to
3201
+ // depend on the substitutions previously applied.
3202
+ auto substTy = partialSubstTy.subst (opaqueRoot->getSubstitutions ());
3203
+
3201
3204
// If the type changed, but still contains opaque types, recur.
3202
3205
if (!substTy->isEqual (maybeOpaqueType) && substTy->hasOpaqueArchetype ()) {
3203
3206
return ::substOpaqueTypesWithUnderlyingTypes (
@@ -3264,18 +3267,12 @@ operator()(CanType maybeOpaqueType, Type replacementType,
3264
3267
// archetype in question. This will map the inner generic signature of the
3265
3268
// opaque type to its outer signature.
3266
3269
auto partialSubstTy = archetype->getInterfaceType ().subst (*subs);
3267
- auto partialSubstRef =
3268
- abstractRef.subst (archetype->getInterfaceType (), *subs);
3269
-
3270
- // Then apply the substitutions from the root opaque archetype, to specialize
3271
- // for its type arguments.
3272
- auto substTy = partialSubstTy.subst (opaqueRoot->getSubstitutions ());
3273
3270
3274
3271
// Check that we are allowed to substitute the underlying type into the
3275
3272
// context.
3276
3273
auto inContext = this ->inContext ;
3277
3274
auto isContextWholeModule = this ->isContextWholeModule ;
3278
- if (substTy .findIf (
3275
+ if (partialSubstTy .findIf (
3279
3276
[inContext, substitutionKind, isContextWholeModule](Type t) -> bool {
3280
3277
if (!canSubstituteTypeInto (t, inContext, substitutionKind,
3281
3278
isContextWholeModule))
@@ -3284,6 +3281,14 @@ operator()(CanType maybeOpaqueType, Type replacementType,
3284
3281
}))
3285
3282
return abstractRef;
3286
3283
3284
+ // Then apply the substitutions from the root opaque archetype, to specialize
3285
+ // for its type arguments. We perform this substitution after checking for
3286
+ // visibility, since we do not want the result of the visibility check to
3287
+ // depend on the substitutions previously applied.
3288
+ auto substTy = partialSubstTy.subst (opaqueRoot->getSubstitutions ());
3289
+
3290
+ auto partialSubstRef =
3291
+ abstractRef.subst (archetype->getInterfaceType (), *subs);
3287
3292
auto substRef =
3288
3293
partialSubstRef.subst (partialSubstTy, opaqueRoot->getSubstitutions ());
3289
3294
0 commit comments