@@ -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
@@ -514,22 +519,19 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
514
519
if (!PlatformKind.hasValue () && Platform == " swift" ) {
515
520
if (PlatformAgnostic == PlatformAgnosticAvailabilityKind::Deprecated) {
516
521
diagnose (AttrLoc,
517
- diag::attr_availability_swift_platform_deprecated ,
522
+ diag::attr_availability_swift_expected_deprecated_version ,
518
523
AttrName);
519
524
return nullptr ;
520
525
}
521
526
if (PlatformAgnostic == PlatformAgnosticAvailabilityKind::Unavailable) {
522
- diagnose (AttrLoc,
523
- diag::attr_availability_swift_platform_infeasible,
524
- " unavailable" ,
525
- AttrName);
527
+ diagnose (AttrLoc, diag::attr_availability_swift_infeasible_option,
528
+ " unavailable" , AttrName);
526
529
return nullptr ;
527
530
}
528
531
assert (PlatformAgnostic == PlatformAgnosticAvailabilityKind::None);
529
532
530
533
if (!SomeVersion) {
531
- diagnose (AttrLoc,
532
- diag::attr_availability_swift_platform_expected_option,
534
+ diagnose (AttrLoc, diag::attr_availability_swift_expected_option,
533
535
AttrName);
534
536
return nullptr ;
535
537
}
@@ -547,21 +549,30 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
547
549
return nullptr ;
548
550
}
549
551
550
- // Warn if any version is specified for non-specific '*' platforms .
552
+ // Warn if any version is specified for non-specific platform '*'.
551
553
if (Platform == " *" && SomeVersion) {
552
- diagnose (AttrLoc,
553
- diag::attr_availability_nonspecific_platform_unexpected_version,
554
- AttrName);
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 ));
555
566
return nullptr ;
556
567
}
557
568
558
569
auto Attr = new (Context)
559
570
AvailableAttr (AtLoc, SourceRange (AttrLoc, Tok.getLoc ()),
560
571
PlatformKind.getValue (),
561
572
Message, Renamed,
562
- Introduced, IntroducedRange ,
563
- Deprecated, DeprecatedRange ,
564
- Obsoleted, ObsoletedRange ,
573
+ Introduced. Version , Introduced. Range ,
574
+ Deprecated. Version , Deprecated. Range ,
575
+ Obsoleted. Version , Obsoleted. Range ,
565
576
PlatformAgnostic,
566
577
/* Implicit=*/ false );
567
578
return makeParserResult (Attr);
0 commit comments