Skip to content

Commit 19eb8d2

Browse files
committed
SIL Parser: Update for subclass existentials
Tested by an upcoming patch that adds IRGen SIL tests.
1 parent 9463b60 commit 19eb8d2

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,10 @@ ERROR(sil_member_decl_type_mismatch,none,
528528
"member defined with mismatching type %0 (expected %1)", (Type, Type))
529529
ERROR(sil_substitution_mismatch,none,
530530
"substitution replacement type %0 does not conform to protocol %1",
531-
(Type, DeclName))
531+
(Type, Type))
532+
ERROR(sil_not_class,none,
533+
"substitution replacement type %0 is not a class type",
534+
(Type))
532535
ERROR(sil_missing_substitutions,none,
533536
"missing substitutions", ())
534537
ERROR(sil_too_many_substitutions,none,

lib/Parse/ParseSIL.cpp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "swift/AST/ASTWalker.h"
14+
#include "swift/AST/ExistentialLayout.h"
1415
#include "swift/AST/GenericEnvironment.h"
1516
#include "swift/AST/NameLookup.h"
1617
#include "swift/AST/ProtocolConformance.h"
@@ -1437,21 +1438,23 @@ bool SILParser::parseSubstitutions(SmallVectorImpl<ParsedSubstitution> &parsed,
14371438
/// Collect conformances by looking up the conformance from replacement
14381439
/// type and protocol decl.
14391440
static bool getConformancesForSubstitution(Parser &P,
1440-
ArrayRef<ProtocolDecl *> protocols,
1441+
ArrayRef<ProtocolType *> protocols,
14411442
Type subReplacement,
14421443
SourceLoc loc,
14431444
SmallVectorImpl<ProtocolConformanceRef> &conformances) {
14441445
auto M = P.SF.getParentModule();
14451446

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);
14481451
if (conformance) {
14491452
conformances.push_back(*conformance);
14501453
continue;
14511454
}
14521455

14531456
P.diagnose(loc, diag::sil_substitution_mismatch, subReplacement,
1454-
proto->getName());
1457+
protoTy);
14551458
return true;
14561459
}
14571460

@@ -1485,11 +1488,9 @@ bool getApplySubstitutionsFromParsed(
14851488
parses = parses.slice(1);
14861489

14871490
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>());
14931494

14941495
if (getConformancesForSubstitution(SP.P, protocols,
14951496
parsed.replacement,
@@ -1515,8 +1516,18 @@ bool getApplySubstitutionsFromParsed(
15151516
static ArrayRef<ProtocolConformanceRef>
15161517
collectExistentialConformances(Parser &P, CanType conformingType, SourceLoc loc,
15171518
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();
15201531
if (protocols.empty())
15211532
return {};
15221533

0 commit comments

Comments
 (0)