@@ -396,8 +396,7 @@ CanType TypeJoin::visitProtocolCompositionType(CanType second) {
396
396
assert (First != second);
397
397
398
398
// FIXME: Handle other types here.
399
- if (!First->is <ProtocolType>() &&
400
- !First->is <ProtocolCompositionType>())
399
+ if (!First->isExistentialType ())
401
400
return TheAnyType;
402
401
403
402
SmallVector<Type, 1 > protocolType;
@@ -413,32 +412,6 @@ CanType TypeJoin::visitProtocolCompositionType(CanType second) {
413
412
return computeProtocolCompositionJoin (firstMembers, secondMembers);
414
413
}
415
414
416
- // Return true if the first ProtocolDecl is a supertype of the second.
417
- static bool isSupertypeOf (ProtocolDecl *super, ProtocolDecl *sub) {
418
- if (super == sub)
419
- return true ;
420
-
421
- SmallVector<ProtocolDecl *, 4 > worklist;
422
- for (auto *decl : sub->getInheritedProtocols ())
423
- worklist.push_back (decl);
424
-
425
- llvm::SmallPtrSet<ProtocolDecl *, 4 > visited;
426
- while (!worklist.empty ()) {
427
- auto *entry = worklist.pop_back_val ();
428
- if (visited.count (entry))
429
- continue ;
430
- visited.insert (entry);
431
-
432
- if (entry == super)
433
- return true ;
434
-
435
- for (auto *decl : entry->getInheritedProtocols ())
436
- worklist.push_back (decl);
437
- }
438
-
439
- return false ;
440
- }
441
-
442
415
CanType TypeJoin::visitProtocolType (CanType second) {
443
416
assert (First != second);
444
417
@@ -459,12 +432,12 @@ CanType TypeJoin::visitProtocolType(CanType second) {
459
432
secondDecl->getInheritedProtocols ().empty ())
460
433
return TheAnyType;
461
434
462
- if (isSupertypeOf (firstDecl, secondDecl))
463
- return First;
464
-
465
- if (isSupertypeOf (secondDecl, firstDecl))
435
+ if (firstDecl->inheritsFrom (secondDecl))
466
436
return second;
467
437
438
+ if (secondDecl->inheritsFrom (firstDecl))
439
+ return First;
440
+
468
441
// One isn't the supertype of the other, so instead, treat each as
469
442
// if it's a protocol composition of its inherited members, and join
470
443
// those.
0 commit comments