Skip to content

Commit 1a0e1ad

Browse files
committed
[cxx-interop] Don't synthesize conformance to invalid protocols.
1 parent 665d3e1 commit 1a0e1ad

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/AST/ProtocolConformance.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,9 @@ void NominalTypeDecl::prepareConformanceTable() const {
10531053
SmallPtrSet<ProtocolDecl *, 2> protocols;
10541054

10551055
auto addSynthesized = [&](ProtocolDecl *proto) {
1056+
if (!proto)
1057+
return;
1058+
10561059
if (protocols.count(proto) == 0) {
10571060
ConformanceTable->addSynthesizedConformance(
10581061
mutableThis, proto, mutableThis);

lib/ClangImporter/ImportDecl.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,13 @@ void ClangImporter::Implementation::addSynthesizedProtocolAttrs(
429429
auto &ctx = nominal->getASTContext();
430430

431431
for (auto kind : synthesizedProtocolAttrs) {
432-
nominal->getAttrs().add(
433-
new (ctx) SynthesizedProtocolAttr(ctx.getProtocol(kind), this, isUnchecked));
432+
// This is unfortunately not an error because some test use mock protocols.
433+
// If those tests were updated, we could assert that
434+
// ctx.getProtocol(kind) != nulltpr which would be nice.
435+
if (auto proto = ctx.getProtocol(kind))
436+
nominal->getAttrs().add(
437+
new (ctx) SynthesizedProtocolAttr(ctx.getProtocol(kind), this,
438+
isUnchecked));
434439
}
435440
}
436441

0 commit comments

Comments
 (0)