@@ -2596,31 +2596,36 @@ namespace {
2596
2596
bool implicit) {
2597
2597
// The constructor was opened with the allocating type, not the
2598
2598
// initializer type. Map the former into the latter.
2599
- auto *resultTy =
2600
- solution.simplifyType (openedFullType)->castTo <FunctionType>();
2601
-
2602
- const auto selfTy = getBaseType (resultTy);
2603
-
2604
- ParameterTypeFlags flags;
2605
- if (!selfTy->hasReferenceSemantics ())
2606
- flags = flags.withInOut (true );
2599
+ auto getOpenedInitializerType = [&](Type ty) -> FunctionType * {
2600
+ auto *resultTy = solution.simplifyType (ty)->castTo <FunctionType>();
2601
+ auto selfTy = getBaseType (resultTy);
2602
+
2603
+ ParameterTypeFlags flags;
2604
+ if (!selfTy->hasReferenceSemantics ())
2605
+ flags = flags.withInOut (true );
2606
+
2607
+ auto selfParam = AnyFunctionType::Param (selfTy, Identifier (), flags);
2608
+ return FunctionType::get ({selfParam},
2609
+ resultTy->getResult (),
2610
+ resultTy->getExtInfo ());
2611
+ };
2607
2612
2608
- auto selfParam = AnyFunctionType::Param (selfTy, Identifier (), flags);
2609
- resultTy = FunctionType::get ({selfParam}, resultTy->getResult (),
2610
- resultTy->getExtInfo ());
2613
+ auto *resultTySelf = getOpenedInitializerType (
2614
+ openedFullType->eraseDynamicSelfType ());
2611
2615
2612
2616
// Build the constructor reference.
2613
2617
Expr *ctorRef = cs.cacheType (
2614
- new (ctx) OtherConstructorDeclRefExpr (ref, loc, implicit, resultTy));
2618
+ new (ctx) OtherConstructorDeclRefExpr (ref, loc, implicit, resultTySelf));
2619
+
2620
+ auto *resultTy = getOpenedInitializerType (
2621
+ openedFullType->replaceDynamicSelfType (
2622
+ cs.getType (base)->getWithoutSpecifierType ()));
2615
2623
2616
2624
// Wrap in covariant `Self` return if needed.
2617
- if (ref.getDecl ()->getDeclContext ()->getSelfClassDecl ()) {
2618
- ASSERT (resultTy->hasDynamicSelfType ());
2619
- auto covariantTy = resultTy->replaceDynamicSelfType (
2620
- cs.getType (base)->getWithoutSpecifierType ());
2621
- if (!covariantTy->isEqual (resultTy))
2622
- ctorRef = cs.cacheType (
2623
- new (ctx) CovariantFunctionConversionExpr (ctorRef, covariantTy));
2625
+ if (!resultTy->isEqual (resultTySelf)) {
2626
+ ASSERT (ref.getDecl ()->getDeclContext ()->getSelfClassDecl ());
2627
+ ctorRef = cs.cacheType (
2628
+ new (ctx) CovariantFunctionConversionExpr (ctorRef, resultTy));
2624
2629
}
2625
2630
2626
2631
return ctorRef;
0 commit comments