Skip to content

Commit 12724e1

Browse files
authored
Merge pull request #79479 from tshortli/assorted-availability-spec-fixes
AST/Parse: Assorted availability spec fixes
2 parents 63b7f05 + efab3ff commit 12724e1

File tree

5 files changed

+26
-37
lines changed

5 files changed

+26
-37
lines changed

lib/AST/ASTDumper.cpp

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,40 +1102,19 @@ namespace {
11021102
void printRec(AvailabilitySpec *Spec, Label label) {
11031103
printRecArbitrary(
11041104
[&](Label label) {
1105-
switch (Spec->getKind()) {
1106-
case AvailabilitySpecKind::PlatformVersionConstraint: {
1107-
printHead("platform_version_constraint_availability_spec",
1108-
PatternColor, label);
1109-
printField(platformString(Spec->getPlatform()),
1110-
Label::always("platform"));
1105+
printHead("availability_spec", PatternColor, label);
1106+
StringRef domainName =
1107+
Spec->isWildcard()
1108+
? "*"
1109+
: Spec->getDomain()->getNameForAttributePrinting();
1110+
printField(domainName, Label::always("domain"));
1111+
if (!Spec->getVersion().empty())
11111112
printFieldRaw(
11121113
[&](llvm::raw_ostream &OS) { OS << Spec->getVersion(); },
11131114
Label::always("version"));
1114-
printFoot();
1115-
break;
1116-
}
1117-
case AvailabilitySpecKind::LanguageVersionConstraint:
1118-
case AvailabilitySpecKind::PackageDescriptionVersionConstraint: {
1119-
printHead("platform_agnostic_version_constraint_"
1120-
"availability_spec",
1121-
PatternColor, label);
1122-
printField(Spec->getDomain()->isSwiftLanguage()
1123-
? "swift"
1124-
: "package_description",
1125-
Label::always("kind"));
1126-
printFieldRaw(
1127-
[&](llvm::raw_ostream &OS) { OS << Spec->getVersion(); },
1128-
Label::always("version"));
1129-
printFoot();
1130-
break;
1131-
}
1132-
case AvailabilitySpecKind::Wildcard:
1133-
printHead("wildcard_constraint_availability_spec", PatternColor,
1134-
label);
1135-
printFoot();
1136-
break;
1137-
}
1138-
}, label);
1115+
printFoot();
1116+
},
1117+
label);
11391118
}
11401119

11411120
/// Print a range of nodes as a single "array" child node.

lib/AST/Decl.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6671,10 +6671,9 @@ bool EnumDecl::hasOnlyCasesWithoutAssociatedValues() const {
66716671
bool hasAssociatedValues = false;
66726672

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

66796678
if (!elt->isAvailableDuringLowering())
66806679
hasAnyUnavailableDuringLoweringValues = true;

lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,9 +1542,7 @@ Parser::parseAvailabilitySpecList(SmallVectorImpl<AvailabilitySpec *> &Specs,
15421542
// If this was preceded by a single platform version constraint, we
15431543
// can guess that the intention was to treat it as 'introduced' and
15441544
// suggest a fix-it to combine them.
1545-
if (Specs.size() == 1 &&
1546-
Previous->getPlatform() != PlatformKind::none &&
1547-
Text != "introduced") {
1545+
if (Specs.size() == 1 && Text != "introduced") {
15481546
auto PlatformNameEndLoc = Lexer::getLocForEndOfToken(
15491547
SourceManager, Previous->getStartLoc());
15501548

test/Parse/diagnose_availability.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ func swiftDeprecatedObsoleted() {}
6464
// expected-warning@-1 {{expected 'introduced', 'deprecated', or 'obsoleted' in 'available' attribute for platform 'swift'}}
6565
func swiftMessage() {}
6666

67+
@available(swift 5, deprecated: 6)
68+
// expected-error@-1 {{'deprecated' can't be combined with shorthand specification 'swift 5'}}
69+
// expected-note@-2 {{did you mean to specify an introduction version?}} {{17-17=, introduced:}}
70+
// expected-error@-3 {{expected declaration}}
71+
func swiftShorthandFollowedByDeprecated() {}
72+
6773
@available(*, unavailable, message: "\("message")")
6874
// expected-error@-1{{'message' cannot be an interpolated string literal}}
6975
func interpolatedMessage() {}

test/attr/attr_availability_swiftpm_v4.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,10 @@ unconditionallyRenamed() // expected-error {{'unconditionallyRenamed()' has been
7979
func unconditionallyRenamedAndIntroducedLater() {} // expected-note {{'unconditionallyRenamedAndIntroducedLater()' has been explicitly marked unavailable here}}
8080

8181
unconditionallyRenamedAndIntroducedLater() // expected-error {{'unconditionallyRenamedAndIntroducedLater()' has been renamed to 'shortFour'}}
82+
83+
func testQuery() {
84+
if #available(_PackageDescription 4.0) { // expected-error {{PackageDescription version checks not allowed in #available(...)}}
85+
// expected-error@-1 {{condition required for target platform}}
86+
shortFourPointOh()
87+
}
88+
}

0 commit comments

Comments
 (0)