@@ -2596,31 +2596,36 @@ namespace {
25962596 bool implicit) {
25972597 // The constructor was opened with the allocating type, not the
25982598 // 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+ };
26072612
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 ());
26112615
26122616 // Build the constructor reference.
26132617 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 ()));
26152623
26162624 // 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));
26242629 }
26252630
26262631 return ctorRef;
0 commit comments