11
11
// ===----------------------------------------------------------------------===//
12
12
13
13
#include " swift/AST/ASTWalker.h"
14
+ #include " swift/AST/ExistentialLayout.h"
14
15
#include " swift/AST/GenericEnvironment.h"
15
16
#include " swift/AST/NameLookup.h"
16
17
#include " swift/AST/ProtocolConformance.h"
@@ -1437,21 +1438,23 @@ bool SILParser::parseSubstitutions(SmallVectorImpl<ParsedSubstitution> &parsed,
1437
1438
// / Collect conformances by looking up the conformance from replacement
1438
1439
// / type and protocol decl.
1439
1440
static bool getConformancesForSubstitution (Parser &P,
1440
- ArrayRef<ProtocolDecl *> protocols,
1441
+ ArrayRef<ProtocolType *> protocols,
1441
1442
Type subReplacement,
1442
1443
SourceLoc loc,
1443
1444
SmallVectorImpl<ProtocolConformanceRef> &conformances) {
1444
1445
auto M = P.SF .getParentModule ();
1445
1446
1446
- for (auto proto : protocols) {
1447
- auto conformance = M->lookupConformance (subReplacement, proto, nullptr );
1447
+ for (auto protoTy : protocols) {
1448
+ auto conformance = M->lookupConformance (subReplacement,
1449
+ protoTy->getDecl (),
1450
+ nullptr );
1448
1451
if (conformance) {
1449
1452
conformances.push_back (*conformance);
1450
1453
continue ;
1451
1454
}
1452
1455
1453
1456
P.diagnose (loc, diag::sil_substitution_mismatch, subReplacement,
1454
- proto-> getName () );
1457
+ protoTy );
1455
1458
return true ;
1456
1459
}
1457
1460
@@ -1485,11 +1488,9 @@ bool getApplySubstitutionsFromParsed(
1485
1488
parses = parses.slice (1 );
1486
1489
1487
1490
SmallVector<ProtocolConformanceRef, 2 > conformances;
1488
- SmallVector<ProtocolDecl *, 2 > protocols;
1489
- for (auto reqt : reqts) {
1490
- protocols.push_back (reqt.getSecondType ()
1491
- ->castTo <ProtocolType>()->getDecl ());
1492
- }
1491
+ SmallVector<ProtocolType *, 2 > protocols;
1492
+ for (auto reqt : reqts)
1493
+ protocols.push_back (reqt.getSecondType ()->castTo <ProtocolType>());
1493
1494
1494
1495
if (getConformancesForSubstitution (SP.P , protocols,
1495
1496
parsed.replacement ,
@@ -1515,8 +1516,18 @@ bool getApplySubstitutionsFromParsed(
1515
1516
static ArrayRef<ProtocolConformanceRef>
1516
1517
collectExistentialConformances (Parser &P, CanType conformingType, SourceLoc loc,
1517
1518
CanType protocolType) {
1518
- SmallVector<ProtocolDecl *, 2 > protocols;
1519
- protocolType.getExistentialTypeProtocols (protocols);
1519
+ auto layout = protocolType.getExistentialLayout ();
1520
+
1521
+ if (layout.requiresClass ) {
1522
+ if (!conformingType->mayHaveSuperclass () &&
1523
+ !conformingType->isObjCExistentialType ()) {
1524
+ P.diagnose (loc, diag::sil_not_class, conformingType);
1525
+ }
1526
+ }
1527
+
1528
+ // FIXME: Check superclass also.
1529
+
1530
+ auto protocols = layout.getProtocols ();
1520
1531
if (protocols.empty ())
1521
1532
return {};
1522
1533
0 commit comments