@@ -6686,18 +6686,38 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl,
6686
6686
if (decl->addedImplicitInitializers ())
6687
6687
return ;
6688
6688
6689
+ // Local function that produces the canonical parameter type of the given
6690
+ // initializer.
6691
+ // FIXME: Doesn't work properly for generics.
6692
+ auto getInitializerParamType = [](ConstructorDecl *ctor) -> CanType {
6693
+ auto interfaceTy = ctor->getInterfaceType ();
6694
+
6695
+ // Skip the 'self' parameter.
6696
+ auto uncurriedInitTy = interfaceTy->castTo <AnyFunctionType>()->getResult ();
6697
+
6698
+ // Grab the parameter type;
6699
+ auto paramTy = uncurriedInitTy->castTo <AnyFunctionType>()->getInput ();
6700
+
6701
+ return paramTy->getCanonicalType ();
6702
+ };
6703
+
6689
6704
// Check whether there is a user-declared constructor or an instance
6690
6705
// variable.
6691
6706
bool FoundInstanceVar = false ;
6692
6707
bool FoundUninitializedVars = false ;
6693
6708
bool FoundDesignatedInit = false ;
6694
6709
decl->setAddedImplicitInitializers ();
6710
+ SmallPtrSet<CanType, 4 > initializerParamTypes;
6695
6711
for (auto member : decl->getMembers ()) {
6696
6712
if (auto ctor = dyn_cast<ConstructorDecl>(member)) {
6713
+ validateDecl (ctor);
6714
+
6697
6715
if (ctor->isDesignatedInit ()) {
6698
6716
FoundDesignatedInit = true ;
6699
- break ;
6700
6717
}
6718
+
6719
+ if (!ctor->isInvalid ())
6720
+ initializerParamTypes.insert (getInitializerParamType (ctor));
6701
6721
continue ;
6702
6722
}
6703
6723
@@ -6761,6 +6781,12 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl,
6761
6781
|| superclassCtor->isInvalid ())
6762
6782
continue ;
6763
6783
6784
+ // If we have already introduced an initializer with this parameter type,
6785
+ // don't add one now.
6786
+ if (!initializerParamTypes.insert (
6787
+ getInitializerParamType (superclassCtor)))
6788
+ continue ;
6789
+
6764
6790
// We have a designated initializer. Create an override of it.
6765
6791
if (auto ctor = createDesignatedInitOverride (
6766
6792
*this , classDecl, superclassCtor,
0 commit comments