Skip to content

Commit

Permalink
Parse/Sema: Consolidate diagnostics for unexpected versions.
Browse files Browse the repository at this point in the history
Since resolving the domain of an `@available` attribute is done during type
checking now, diagnostics about unexpected versions for a domain need to be
emitted at that point instead of during parsing. It doesn't make sense to
maintain the special version of this diagnostic that is emitted during parsing
for the universal availability domain only.
  • Loading branch information
tshortli committed Feb 2, 2025
1 parent c95c452 commit 427c8af
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 30 deletions.
4 changes: 0 additions & 4 deletions include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -1579,10 +1579,6 @@ ERROR(attr_availability_expected_equal,none,
ERROR(attr_availability_expected_version,none,
"expected version number in '%0' attribute", (StringRef))

WARNING(attr_availability_nonspecific_platform_unexpected_version,none,
"unexpected version number in '%0' attribute for non-specific platform "
"'*'", (StringRef))

WARNING(attr_availability_wildcard_ignored,none,
"* as platform name has no effect in '%0' attribute", (StringRef))

Expand Down
20 changes: 0 additions & 20 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,26 +546,6 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
if (AnyArgumentInvalid)
return nullptr;

// Warn if any version is specified with the universal domain ('*').
bool SomeVersion = (!Introduced.empty() ||
!Deprecated.empty() ||
!Obsoleted.empty());
if (Platform == "*" && SomeVersion) {
auto diag = diagnose(AttrLoc,
diag::attr_availability_nonspecific_platform_unexpected_version,
AttrName);
if (!Introduced.empty())
diag.fixItRemove(SourceRange(Introduced.DelimiterLoc,
Introduced.Range.End));
if (!Deprecated.empty())
diag.fixItRemove(SourceRange(Deprecated.DelimiterLoc,
Deprecated.Range.End));
if (!Obsoleted.empty())
diag.fixItRemove(SourceRange(Obsoleted.DelimiterLoc,
Obsoleted.Range.End));
return nullptr;
}

auto Attr = new (Context) AvailableAttr(
AtLoc, SourceRange(AttrLoc, Tok.getLoc()), Platform, PlatformLoc,
AttrKind, Message, Renamed, Introduced.Version, Introduced.Range,
Expand Down
4 changes: 1 addition & 3 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8404,9 +8404,7 @@ SemanticAvailableAttrRequest::evaluate(swift::Evaluator &evaluator,
bool hasVersionSpec =
(introducedVersion || deprecatedVersion || obsoletedVersion);

// FIXME: [availability] For the universal domain, this is currently
// diagnosed during parsing. That diagnostic should be subsumed by this one.
if (!domain->isVersioned() && hasVersionSpec && !domain->isUniversal()) {
if (!domain->isVersioned() && hasVersionSpec) {
SourceRange versionSourceRange;
if (introducedVersion)
versionSourceRange = semanticAttr.getIntroducedSourceRange();
Expand Down
6 changes: 3 additions & 3 deletions test/Parse/diagnose_availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ func twoShorthandsFollowedByDeprecated() {}
// Missing/wrong warning message for '*' or 'swift' platform.

@available(*, deprecated: 4.2)
// expected-warning@-1 {{unexpected version number in 'available' attribute for non-specific platform '*'}} {{25-30=}}
// expected-warning@-1 {{unexpected version number in '@available' attribute for '*'}}
func allPlatformsDeprecatedVersion() {}

@available(*, deprecated, obsoleted: 4.2)
// expected-warning@-1 {{unexpected version number in 'available' attribute for non-specific platform '*'}} {{36-41=}}
// expected-warning@-1 {{unexpected version number in '@available' attribute for '*'}}
func allPlatformsDeprecatedAndObsoleted() {}

@available(*, introduced: 4.0, deprecated: 4.1, obsoleted: 4.2)
// expected-warning@-1 {{unexpected version number in 'available' attribute for non-specific platform '*'}} {{25-30=}} {{42-47=}} {{58-63=}}
// expected-warning@-1 {{unexpected version number in '@available' attribute for '*'}}
func allPlatformsDeprecatedAndObsoleted2() {}

@available(swift, unavailable)
Expand Down

0 comments on commit 427c8af

Please sign in to comment.