@@ -233,19 +233,20 @@ struct SynthesizedExtensionAnalyzer::Implementation {
233
233
for (auto Req : Ext->getGenericSignature ()->getRequirements ()) {
234
234
auto Kind = Req.getKind ();
235
235
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
+ }
244
248
}
245
249
246
- First = First->getCanonicalType ();
247
- Second = Second->getCanonicalType ();
248
-
249
250
switch (Kind) {
250
251
case RequirementKind::Conformance:
251
252
case RequirementKind::Layout:
@@ -934,21 +935,18 @@ class PrintAST : public ASTVisitor<PrintAST> {
934
935
T = Current->getInnermostDeclContext ()->mapTypeOutOfContext (T);
935
936
}
936
937
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;
946
940
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
+ }
948
949
949
- // Get the substitutions from our base type.
950
- auto *M = DC->getParentModule ();
951
- auto subMap = CurrentType->getContextSubstitutionMap (M, DC);
952
950
T = T.subst (subMap, SubstFlags::DesugarMemberTypes);
953
951
}
954
952
0 commit comments