Skip to content

Parse/Sema: Consolidate diagnostics for unexpected versions #79098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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