@@ -4390,6 +4390,32 @@ checkImplicitPromotionsInCondition(const StmtConditionElement &cond,
4390
4390
}
4391
4391
}
4392
4392
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
+
4393
4419
// / Diagnoses a `if #_hasSymbol(...)` condition. Returns true if a diagnostic
4394
4420
// / was emitted.
4395
4421
static bool diagnoseHasSymbolCondition (PoundHasSymbolInfo *info,
@@ -4416,21 +4442,19 @@ static bool diagnoseHasSymbolCondition(PoundHasSymbolInfo *info,
4416
4442
return true ;
4417
4443
}
4418
4444
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 ;
4434
4458
}
4435
4459
4436
4460
auto decl = info->getReferencedDecl ().getDecl ();
@@ -4465,9 +4489,12 @@ static void checkLabeledStmtConditions(ASTContext &ctx,
4465
4489
switch (elt.getKind ()) {
4466
4490
case StmtConditionElement::CK_Boolean:
4467
4491
case StmtConditionElement::CK_PatternBinding:
4468
- case StmtConditionElement::CK_Availability:
4469
4492
break ;
4470
-
4493
+ case StmtConditionElement::CK_Availability: {
4494
+ auto info = elt.getAvailability ();
4495
+ (void )diagnoseAvailabilityCondition (info, DC);
4496
+ break ;
4497
+ }
4471
4498
case StmtConditionElement::CK_HasSymbol: {
4472
4499
auto info = elt.getHasSymbolInfo ();
4473
4500
if (diagnoseHasSymbolCondition (info, DC))
0 commit comments