@@ -4390,6 +4390,32 @@ checkImplicitPromotionsInCondition(const StmtConditionElement &cond,
43904390 }
43914391}
43924392
4393+ // / Diagnoses a `if #available(...)` condition. Returns true if a diagnostic
4394+ // / was emitted.
4395+ static bool diagnoseAvailabilityCondition (PoundAvailableInfo *info,
4396+ DeclContext *DC) {
4397+ // Reject inlinable code using availability macros. In order to lift this
4398+ // restriction, macros would need to either be expanded when printed in
4399+ // swiftinterfaces or be parsable as macros by module clients.
4400+ auto fragileKind = DC->getFragileFunctionKind ();
4401+ if (fragileKind.kind != FragileFunctionKind::None) {
4402+ for (auto queries : info->getQueries ()) {
4403+ if (auto availSpec =
4404+ dyn_cast<PlatformVersionConstraintAvailabilitySpec>(queries)) {
4405+ if (availSpec->getMacroLoc ().isValid ()) {
4406+ DC->getASTContext ().Diags .diagnose (
4407+ availSpec->getMacroLoc (),
4408+ swift::diag::availability_macro_in_inlinable,
4409+ fragileKind.getSelector ());
4410+ return true ;
4411+ }
4412+ }
4413+ }
4414+ }
4415+
4416+ return false ;
4417+ }
4418+
43934419// / Diagnoses a `if #_hasSymbol(...)` condition. Returns true if a diagnostic
43944420// / was emitted.
43954421static bool diagnoseHasSymbolCondition (PoundHasSymbolInfo *info,
@@ -4416,21 +4442,19 @@ static bool diagnoseHasSymbolCondition(PoundHasSymbolInfo *info,
44164442 return true ;
44174443 }
44184444
4419- if (DC->getAsDecl ()) {
4420- auto fragileKind = DC->getFragileFunctionKind ();
4421- if (fragileKind.kind != FragileFunctionKind::None) {
4422- // #_hasSymbol cannot be used in inlinable code because of limitations of
4423- // the current implementation strategy. It relies on recording the
4424- // referenced ValueDecl, mangling a helper function name using that
4425- // ValueDecl, and then passing the responsibility of generating the
4426- // definition for that helper function to IRGen. In order to lift this
4427- // restriction, we will need teach SIL to encode the ValueDecl, or take
4428- // another approach entirely.
4429- ctx.Diags .diagnose (info->getStartLoc (),
4430- diag::has_symbol_condition_in_inlinable,
4431- fragileKind.getSelector ());
4432- return true ;
4433- }
4445+ auto fragileKind = DC->getFragileFunctionKind ();
4446+ if (fragileKind.kind != FragileFunctionKind::None) {
4447+ // #_hasSymbol cannot be used in inlinable code because of limitations of
4448+ // the current implementation strategy. It relies on recording the
4449+ // referenced ValueDecl, mangling a helper function name using that
4450+ // ValueDecl, and then passing the responsibility of generating the
4451+ // definition for that helper function to IRGen. In order to lift this
4452+ // restriction, we will need teach SIL to encode the ValueDecl, or take
4453+ // another approach entirely.
4454+ ctx.Diags .diagnose (info->getStartLoc (),
4455+ diag::has_symbol_condition_in_inlinable,
4456+ fragileKind.getSelector ());
4457+ return true ;
44344458 }
44354459
44364460 auto decl = info->getReferencedDecl ().getDecl ();
@@ -4465,9 +4489,12 @@ static void checkLabeledStmtConditions(ASTContext &ctx,
44654489 switch (elt.getKind ()) {
44664490 case StmtConditionElement::CK_Boolean:
44674491 case StmtConditionElement::CK_PatternBinding:
4468- case StmtConditionElement::CK_Availability:
44694492 break ;
4470-
4493+ case StmtConditionElement::CK_Availability: {
4494+ auto info = elt.getAvailability ();
4495+ (void )diagnoseAvailabilityCondition (info, DC);
4496+ break ;
4497+ }
44714498 case StmtConditionElement::CK_HasSymbol: {
44724499 auto info = elt.getHasSymbolInfo ();
44734500 if (diagnoseHasSymbolCondition (info, DC))
0 commit comments