Skip to content

AST/Parse: Assorted availability spec fixes #79479

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
merged 4 commits into from
Feb 19, 2025
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
41 changes: 10 additions & 31 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,40 +1102,19 @@ namespace {
void printRec(AvailabilitySpec *Spec, Label label) {
printRecArbitrary(
[&](Label label) {
switch (Spec->getKind()) {
case AvailabilitySpecKind::PlatformVersionConstraint: {
printHead("platform_version_constraint_availability_spec",
PatternColor, label);
printField(platformString(Spec->getPlatform()),
Label::always("platform"));
printHead("availability_spec", PatternColor, label);
StringRef domainName =
Spec->isWildcard()
? "*"
: Spec->getDomain()->getNameForAttributePrinting();
printField(domainName, Label::always("domain"));
if (!Spec->getVersion().empty())
printFieldRaw(
[&](llvm::raw_ostream &OS) { OS << Spec->getVersion(); },
Label::always("version"));
printFoot();
break;
}
case AvailabilitySpecKind::LanguageVersionConstraint:
case AvailabilitySpecKind::PackageDescriptionVersionConstraint: {
printHead("platform_agnostic_version_constraint_"
"availability_spec",
PatternColor, label);
printField(Spec->getDomain()->isSwiftLanguage()
? "swift"
: "package_description",
Label::always("kind"));
printFieldRaw(
[&](llvm::raw_ostream &OS) { OS << Spec->getVersion(); },
Label::always("version"));
printFoot();
break;
}
case AvailabilitySpecKind::Wildcard:
printHead("wildcard_constraint_availability_spec", PatternColor,
label);
printFoot();
break;
}
}, label);
printFoot();
},
label);
}

/// Print a range of nodes as a single "array" child node.
Expand Down
5 changes: 2 additions & 3 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6671,10 +6671,9 @@ bool EnumDecl::hasOnlyCasesWithoutAssociatedValues() const {
bool hasAssociatedValues = false;

for (auto elt : getAllElements()) {
for (auto Attr : elt->getSemanticAvailableAttrs()) {
// FIXME: [availability] Deprecation doesn't make an element unavailable
// FIXME: [availability] Deprecation doesn't make an element unavailable
if (!elt->getSemanticAvailableAttrs().empty())
hasAnyUnavailableValues = true;
}

if (!elt->isAvailableDuringLowering())
hasAnyUnavailableDuringLoweringValues = true;
Expand Down
4 changes: 1 addition & 3 deletions lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1542,9 +1542,7 @@ Parser::parseAvailabilitySpecList(SmallVectorImpl<AvailabilitySpec *> &Specs,
// If this was preceded by a single platform version constraint, we
// can guess that the intention was to treat it as 'introduced' and
// suggest a fix-it to combine them.
if (Specs.size() == 1 &&
Previous->getPlatform() != PlatformKind::none &&
Text != "introduced") {
if (Specs.size() == 1 && Text != "introduced") {
auto PlatformNameEndLoc = Lexer::getLocForEndOfToken(
SourceManager, Previous->getStartLoc());

Expand Down
6 changes: 6 additions & 0 deletions test/Parse/diagnose_availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ func swiftDeprecatedObsoleted() {}
// expected-warning@-1 {{expected 'introduced', 'deprecated', or 'obsoleted' in 'available' attribute for platform 'swift'}}
func swiftMessage() {}

@available(swift 5, deprecated: 6)
// expected-error@-1 {{'deprecated' can't be combined with shorthand specification 'swift 5'}}
// expected-note@-2 {{did you mean to specify an introduction version?}} {{17-17=, introduced:}}
// expected-error@-3 {{expected declaration}}
func swiftShorthandFollowedByDeprecated() {}

@available(*, unavailable, message: "\("message")")
// expected-error@-1{{'message' cannot be an interpolated string literal}}
func interpolatedMessage() {}
Expand Down
7 changes: 7 additions & 0 deletions test/attr/attr_availability_swiftpm_v4.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,10 @@ unconditionallyRenamed() // expected-error {{'unconditionallyRenamed()' has been
func unconditionallyRenamedAndIntroducedLater() {} // expected-note {{'unconditionallyRenamedAndIntroducedLater()' has been explicitly marked unavailable here}}

unconditionallyRenamedAndIntroducedLater() // expected-error {{'unconditionallyRenamedAndIntroducedLater()' has been renamed to 'shortFour'}}

func testQuery() {
if #available(_PackageDescription 4.0) { // expected-error {{PackageDescription version checks not allowed in #available(...)}}
// expected-error@-1 {{condition required for target platform}}
shortFourPointOh()
}
}