@@ -315,11 +315,19 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
315
315
return true ;
316
316
};
317
317
318
+ struct VersionArg {
319
+ llvm::VersionTuple Version;
320
+ SourceRange Range;
321
+ SourceLoc DelimiterLoc;
322
+ bool empty () const {
323
+ return Version.empty ();
324
+ }
325
+ };
326
+
318
327
StringRef Platform = Tok.getText ();
319
328
320
329
StringRef Message, Renamed;
321
- llvm::VersionTuple Introduced, Deprecated, Obsoleted;
322
- SourceRange IntroducedRange, DeprecatedRange, ObsoletedRange;
330
+ VersionArg Introduced, Deprecated, Obsoleted;
323
331
auto PlatformAgnostic = PlatformAgnosticAvailabilityKind::None;
324
332
325
333
SyntaxParsingContext AvailabilitySpecContext (
@@ -443,7 +451,9 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
443
451
case IsIntroduced:
444
452
case IsObsoleted: {
445
453
// Items with version arguments.
454
+ SourceLoc DelimiterLoc;
446
455
if (findAttrValueDelimiter ()) {
456
+ DelimiterLoc = Tok.getLoc ();
447
457
consumeToken ();
448
458
} else {
449
459
diagnose (Tok, diag::attr_availability_expected_equal, AttrName,
@@ -454,24 +464,19 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
454
464
break ;
455
465
}
456
466
457
- auto &VersionArg =
467
+ auto &VerArg =
458
468
(ArgumentKind == IsIntroduced)
459
469
? Introduced
460
470
: (ArgumentKind == IsDeprecated) ? Deprecated : Obsoleted;
461
471
462
- auto &VersionRange = (ArgumentKind == IsIntroduced)
463
- ? IntroducedRange
464
- : (ArgumentKind == IsDeprecated)
465
- ? DeprecatedRange
466
- : ObsoletedRange;
467
-
468
472
if (parseVersionTuple (
469
- VersionArg, VersionRange ,
473
+ VerArg. Version , VerArg. Range ,
470
474
Diagnostic (diag::attr_availability_expected_version, AttrName))) {
471
475
AnyArgumentInvalid = true ;
472
476
if (peekToken ().isAny (tok::r_paren, tok::comma))
473
477
consumeToken ();
474
478
}
479
+ VerArg.DelimiterLoc = DelimiterLoc;
475
480
476
481
SyntaxContext->createNodeInPlace (SyntaxKind::AvailabilityLabeledArgument);
477
482
@@ -511,10 +516,26 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
511
516
bool SomeVersion = (!Introduced.empty () ||
512
517
!Deprecated.empty () ||
513
518
!Obsoleted.empty ());
514
- if (!PlatformKind.hasValue () &&
515
- Platform == " swift" &&
516
- SomeVersion &&
517
- PlatformAgnostic == PlatformAgnosticAvailabilityKind::None) {
519
+ if (!PlatformKind.hasValue () && Platform == " swift" ) {
520
+ if (PlatformAgnostic == PlatformAgnosticAvailabilityKind::Deprecated) {
521
+ diagnose (AttrLoc,
522
+ diag::attr_availability_swift_expected_deprecated_version,
523
+ AttrName);
524
+ return nullptr ;
525
+ }
526
+ if (PlatformAgnostic == PlatformAgnosticAvailabilityKind::Unavailable) {
527
+ diagnose (AttrLoc, diag::attr_availability_swift_infeasible_option,
528
+ " unavailable" , AttrName);
529
+ return nullptr ;
530
+ }
531
+ assert (PlatformAgnostic == PlatformAgnosticAvailabilityKind::None);
532
+
533
+ if (!SomeVersion) {
534
+ diagnose (AttrLoc, diag::attr_availability_swift_expected_option,
535
+ AttrName);
536
+ return nullptr ;
537
+ }
538
+
518
539
PlatformKind = PlatformKind::none;
519
540
PlatformAgnostic = PlatformAgnosticAvailabilityKind::SwiftVersionSpecific;
520
541
}
@@ -528,13 +549,30 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
528
549
return nullptr ;
529
550
}
530
551
552
+ // Warn if any version is specified for non-specific platform '*'.
553
+ if (Platform == " *" && SomeVersion) {
554
+ auto diag = diagnose (AttrLoc,
555
+ diag::attr_availability_nonspecific_platform_unexpected_version,
556
+ AttrName);
557
+ if (!Introduced.empty ())
558
+ diag.fixItRemove (SourceRange (Introduced.DelimiterLoc ,
559
+ Introduced.Range .End ));
560
+ if (!Deprecated.empty ())
561
+ diag.fixItRemove (SourceRange (Deprecated.DelimiterLoc ,
562
+ Deprecated.Range .End ));
563
+ if (!Obsoleted.empty ())
564
+ diag.fixItRemove (SourceRange (Obsoleted.DelimiterLoc ,
565
+ Obsoleted.Range .End ));
566
+ return nullptr ;
567
+ }
568
+
531
569
auto Attr = new (Context)
532
570
AvailableAttr (AtLoc, SourceRange (AttrLoc, Tok.getLoc ()),
533
571
PlatformKind.getValue (),
534
572
Message, Renamed,
535
- Introduced, IntroducedRange ,
536
- Deprecated, DeprecatedRange ,
537
- Obsoleted, ObsoletedRange ,
573
+ Introduced. Version , Introduced. Range ,
574
+ Deprecated. Version , Deprecated. Range ,
575
+ Obsoleted. Version , Obsoleted. Range ,
538
576
PlatformAgnostic,
539
577
/* Implicit=*/ false );
540
578
return makeParserResult (Attr);
0 commit comments