@@ -5417,18 +5417,6 @@ void AbstractFunctionDecl::computeType(AnyFunctionType::ExtInfo info) {
5417
5417
5418
5418
// (Self) -> (Args...) -> Result
5419
5419
if (hasSelf) {
5420
- // Constructors have an initializer type that takes an instance
5421
- // instead of a metatype.
5422
- if (auto *ctor = dyn_cast<ConstructorDecl>(this )) {
5423
- auto initSelfParam = computeSelfParam (this , /* isInitializingCtor=*/ true );
5424
- Type initFuncTy;
5425
- if (sig)
5426
- initFuncTy = GenericFunctionType::get (sig, {initSelfParam}, funcTy);
5427
- else
5428
- initFuncTy = FunctionType::get ({initSelfParam}, funcTy);
5429
- ctor->setInitializerInterfaceType (initFuncTy);
5430
- }
5431
-
5432
5420
// Substitute in our own 'self' parameter.
5433
5421
auto selfParam = computeSelfParam (this );
5434
5422
if (sig)
@@ -5806,11 +5794,24 @@ Type ConstructorDecl::getResultInterfaceType() const {
5806
5794
}
5807
5795
5808
5796
Type ConstructorDecl::getInitializerInterfaceType () {
5809
- return InitializerInterfaceType;
5810
- }
5797
+ if ( InitializerInterfaceType)
5798
+ return InitializerInterfaceType;
5811
5799
5812
- void ConstructorDecl::setInitializerInterfaceType (Type t) {
5813
- InitializerInterfaceType = t;
5800
+ // Lazily calculate initializer type.
5801
+ auto funcTy = getInterfaceType ()->castTo <AnyFunctionType>()->getResult ();
5802
+ assert (funcTy->is <FunctionType>());
5803
+
5804
+ // Constructors have an initializer type that takes an instance
5805
+ // instead of a metatype.
5806
+ auto initSelfParam = computeSelfParam (this , /* isInitializingCtor=*/ true );
5807
+ Type initFuncTy;
5808
+ if (auto *sig = getGenericSignature ())
5809
+ initFuncTy = GenericFunctionType::get (sig, {initSelfParam}, funcTy);
5810
+ else
5811
+ initFuncTy = FunctionType::get ({initSelfParam}, funcTy);
5812
+ InitializerInterfaceType = initFuncTy;
5813
+
5814
+ return InitializerInterfaceType;
5814
5815
}
5815
5816
5816
5817
ConstructorDecl::BodyInitKind
0 commit comments