Skip to content

Commit 872d473

Browse files
committed
AST: Use the right SubstitutionMap for the type we're printing
1 parent 0534ae1 commit 872d473

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,20 @@ struct SynthesizedExtensionAnalyzer::Implementation {
233233
for (auto Req : Ext->getGenericSignature()->getRequirements()) {
234234
auto Kind = Req.getKind();
235235

236-
Type First = Req.getFirstType().subst(subMap);
237-
Type Second = Req.getSecondType().subst(subMap);
238-
239-
if (!First || !Second) {
240-
// Substitution with interface type bases can only fail
241-
// if a concrete type fails to conform to a protocol.
242-
// In this case, just give up on the extension altogether.
243-
return {Result, MergeInfo};
236+
auto First = Req.getFirstType();
237+
auto Second = Req.getSecondType();
238+
if (!BaseType->isExistentialType()) {
239+
First = First.subst(subMap);
240+
Second = Second.subst(subMap);
241+
242+
if (!First || !Second) {
243+
// Substitution with interface type bases can only fail
244+
// if a concrete type fails to conform to a protocol.
245+
// In this case, just give up on the extension altogether.
246+
return {Result, MergeInfo};
247+
}
244248
}
245249

246-
First = First->getCanonicalType();
247-
Second = Second->getCanonicalType();
248-
249250
switch (Kind) {
250251
case RequirementKind::Conformance:
251252
case RequirementKind::Layout:
@@ -934,21 +935,18 @@ class PrintAST : public ASTVisitor<PrintAST> {
934935
T = Current->getInnermostDeclContext()->mapTypeOutOfContext(T);
935936
}
936937

937-
// Get the innermost nominal type context.
938-
DeclContext *DC;
939-
if (isa<NominalTypeDecl>(Current))
940-
DC = Current->getInnermostDeclContext();
941-
else if (isa<ExtensionDecl>(Current))
942-
DC = Current->getInnermostDeclContext()->
943-
getAsNominalTypeOrNominalTypeExtensionContext();
944-
else
945-
DC = Current->getDeclContext();
938+
auto *M = Current->getDeclContext()->getParentModule();
939+
SubstitutionMap subMap;
946940

947-
assert(DC->isTypeContext());
941+
if (auto *NTD = dyn_cast<NominalTypeDecl>(Current))
942+
subMap = CurrentType->getContextSubstitutionMap(M, NTD);
943+
else if (auto *ED = dyn_cast<ExtensionDecl>(Current))
944+
subMap = CurrentType->getContextSubstitutionMap(M, ED);
945+
else {
946+
subMap = CurrentType->getMemberSubstitutionMap(
947+
M, cast<ValueDecl>(Current));
948+
}
948949

949-
// Get the substitutions from our base type.
950-
auto *M = DC->getParentModule();
951-
auto subMap = CurrentType->getContextSubstitutionMap(M, DC);
952950
T = T.subst(subMap, SubstFlags::DesugarMemberTypes);
953951
}
954952

0 commit comments

Comments
 (0)