Skip to content

Commit 2eb31fa

Browse files
committed
Sema: Don't overwrite parameter types in createDesignatedInitOverride()
1 parent a06e5d0 commit 2eb31fa

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -648,20 +648,27 @@ createDesignatedInitOverride(ClassDecl *classDecl,
648648
// Determine the initializer parameters.
649649

650650
// Create the initializer parameter patterns.
651-
OptionSet<ParameterList::CloneFlags> options = ParameterList::Implicit;
652-
options |= ParameterList::Inherited;
653-
auto *bodyParams = superclassCtor->getParameters()->clone(ctx, options);
651+
OptionSet<ParameterList::CloneFlags> options
652+
= (ParameterList::Implicit |
653+
ParameterList::Inherited |
654+
ParameterList::WithoutTypes);
655+
auto *superclassParams = superclassCtor->getParameters();
656+
auto *bodyParams = superclassParams->clone(ctx, options);
654657

655658
// If the superclass is generic, we need to map the superclass constructor's
656659
// parameter types into the generic context of our class.
657660
//
658661
// We might have to apply substitutions, if for example we have a declaration
659662
// like 'class A : B<Int>'.
660-
for (auto *decl : *bodyParams) {
661-
auto paramTy = decl->getInterfaceType();
663+
for (unsigned idx : range(superclassParams->size())) {
664+
auto *superclassParam = superclassParams->get(idx);
665+
auto *bodyParam = bodyParams->get(idx);
666+
667+
auto paramTy = superclassParam->getInterfaceType();
662668
auto substTy = paramTy.subst(subMap, SubstFlags::UseErrorType);
663-
decl->setInterfaceType(substTy);
664-
decl->getTypeLoc() = TypeLoc::withoutLoc(substTy);
669+
670+
bodyParam->setInterfaceType(substTy);
671+
bodyParam->getTypeLoc() = TypeLoc::withoutLoc(substTy);
665672
}
666673

667674
// Create the initializer declaration, inheriting the name,

0 commit comments

Comments
 (0)