Skip to content

Commit c5840e8

Browse files
authored
Merge pull request #70749 from tshortli/unavailable-code-reached-diagnostic-synthesis
Sema: Allow _diagnoseUnavailableCodeReached() to not exist in the stdlib
2 parents 987756c + c464741 commit c5840e8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/Sema/DerivedConformances.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ DerivedConformance::createBuiltinCall(ASTContext &ctx,
496496
CallExpr *DerivedConformance::createDiagnoseUnavailableCodeReachedCallExpr(
497497
ASTContext &ctx) {
498498
FuncDecl *diagnoseDecl = ctx.getDiagnoseUnavailableCodeReachedDecl();
499+
assert(diagnoseDecl);
499500
auto diagnoseDeclRefExpr =
500501
new (ctx) DeclRefExpr(diagnoseDecl, DeclNameLoc(), true);
501502
diagnoseDeclRefExpr->setType(diagnoseDecl->getInterfaceType());
@@ -939,6 +940,12 @@ CaseStmt *DerivedConformance::unavailableEnumElementCaseStmt(
939940
if (!availableAttr->isUnconditionallyUnavailable())
940941
return nullptr;
941942

943+
// If the stdlib isn't new enough to contain the helper function for
944+
// diagnosing execution of unavailable code then just synthesize this case
945+
// normally.
946+
if (!C.getDiagnoseUnavailableCodeReachedDecl())
947+
return nullptr;
948+
942949
auto createElementPattern = [&]() -> EnumElementPattern * {
943950
// .<elt>
944951
EnumElementPattern *eltPattern = new (C) EnumElementPattern(

0 commit comments

Comments
 (0)