@@ -66,6 +66,7 @@ struct TypeJoin : CanTypeVisitor<TypeJoin, CanType> {
66
66
CanType visitBoundGenericStructType (CanType second);
67
67
CanType visitMetatypeType (CanType second);
68
68
CanType visitExistentialMetatypeType (CanType second);
69
+ CanType visitExistentialType (CanType second);
69
70
CanType visitModuleType (CanType second);
70
71
CanType visitDynamicSelfType (CanType second);
71
72
CanType visitArchetypeType (CanType second);
@@ -271,6 +272,29 @@ CanType TypeJoin::visitExistentialMetatypeType(CanType second) {
271
272
return ExistentialMetatypeType::get (joinInstance)->getCanonicalType ();
272
273
}
273
274
275
+ CanType TypeJoin::visitExistentialType (CanType second) {
276
+ assert (First != second);
277
+
278
+ if (First->getKind () != second->getKind ())
279
+ return TheAnyType;
280
+
281
+ auto firstConstraint = First->castTo <ExistentialType>()
282
+ ->getConstraintType ()->getCanonicalType ();
283
+ auto secondConstraint = second->castTo <ExistentialType>()
284
+ ->getConstraintType ()->getCanonicalType ();
285
+
286
+ auto joinInstance = join (firstConstraint, secondConstraint);
287
+ if (!joinInstance)
288
+ return CanType ();
289
+
290
+ if (joinInstance->is <ExistentialMetatypeType>() ||
291
+ joinInstance->isAny () ||
292
+ joinInstance->isAnyObject ())
293
+ return joinInstance;
294
+
295
+ return ExistentialType::get (joinInstance)->getCanonicalType ();
296
+ }
297
+
274
298
CanType TypeJoin::visitModuleType (CanType second) {
275
299
assert (First != second);
276
300
0 commit comments