Skip to content

Commit 6492aaf

Browse files
committed
Revert changes to trailing commas in attributes like @available
1 parent 1a3d71c commit 6492aaf

13 files changed

+40
-109
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,6 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
535535
// Parse the trailing comma
536536
if (consumeIf(tok::comma)) {
537537
HasUpcomingEntry = true;
538-
539-
// If this is a trailing comma then there are no more entries
540-
if (Tok.is(tok::r_paren)) {
541-
break;
542-
}
543538
} else {
544539
HasUpcomingEntry = false;
545540
}
@@ -1013,11 +1008,6 @@ Parser::parseStorageRestrictionsAttribute(SourceLoc AtLoc, SourceLoc Loc) {
10131008

10141009
// Parse the comma, if the list continues.
10151010
hasNextProperty = consumeIf(tok::comma);
1016-
1017-
// If this was a trailing comma, the list is complete.
1018-
if (Tok.is(tok::r_paren)) {
1019-
break;
1020-
}
10211011
} while (hasNextProperty);
10221012

10231013
return status;
@@ -2025,7 +2015,7 @@ bool Parser::parseBackDeployedAttribute(DeclAttributes &Attributes,
20252015
do {
20262016
Result = parseListItem(
20272017
Status, tok::r_paren, LeftLoc, RightLoc,
2028-
/*AllowSepAfterLast=*/true, [&]() -> ParserStatus {
2018+
/*AllowSepAfterLast=*/false, [&]() -> ParserStatus {
20292019
return parsePlatformVersionInList(AtAttrName, PlatformAndVersions,
20302020
ParsedUnrecognizedPlatformName);
20312021
});
@@ -2267,7 +2257,7 @@ Parser::parseMacroRoleAttribute(
22672257
SmallVector<Expr *, 2> conformances;
22682258
auto argumentsStatus = parseList(
22692259
tok::r_paren, lParenLoc, rParenLoc,
2270-
/*AllowSepAfterLast=*/true, diag::expected_rparen_expr_list, [&] {
2260+
/*AllowSepAfterLast=*/false, diag::expected_rparen_expr_list, [&] {
22712261
ParserStatus status;
22722262

22732263
if (consumeIf(tok::code_complete)) {
@@ -3256,7 +3246,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
32563246
bool SuppressLaterDiags = false;
32573247
bool ParsedUnrecognizedPlatformName = false;
32583248
if (parseList(tok::r_paren, LeftLoc, RightLoc,
3259-
/*AllowSepAfterLast=*/true,
3249+
/*AllowSepAfterLast=*/false,
32603250
diag::originally_defined_in_missing_rparen,
32613251
[&]() -> ParserStatus {
32623252
SWIFT_DEFER {
@@ -4989,7 +4979,7 @@ ParserResult<LifetimeEntry> Parser::parseLifetimeEntry(SourceLoc loc) {
49894979
SourceLoc rParenLoc;
49904980
bool foundParamId = false;
49914981
status = parseList(
4992-
tok::r_paren, lParenLoc, rParenLoc, /*AllowSepAfterLast=*/true,
4982+
tok::r_paren, lParenLoc, rParenLoc, /*AllowSepAfterLast=*/false,
49934983
diag::expected_rparen_after_lifetime_dependence, [&]() -> ParserStatus {
49944984
ParserStatus listStatus;
49954985
foundParamId = true;

lib/Parse/ParseStmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,8 +1445,8 @@ Parser::parseAvailabilitySpecList(SmallVectorImpl<AvailabilitySpec *> &Specs,
14451445
consumeToken();
14461446
Status.setIsParseError();
14471447
} else if (consumeIf(tok::comma)) {
1448-
// End of spec list with a trailing comma.
1449-
if (Tok.is(tok::r_paren)) {
1448+
// End of unavailable spec list with a trailing comma.
1449+
if (Source == AvailabilitySpecSource::Unavailable && Tok.is(tok::r_paren)) {
14501450
break;
14511451
}
14521452
// There is more to parse in this list.

lib/Parse/ParseType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ ParserResult<TypeRepr> Parser::parseTypeSimple(
194194
SourceLoc rbLoc;
195195
SmallVector<TypeRepr *, 8> elements;
196196
auto status = parseList(tok::r_brace, lbLoc, rbLoc,
197-
/*AllowSepAfterLast=*/true,
197+
/*AllowSepAfterLast=*/false,
198198
diag::expected_rbrace_pack_type_list,
199199
[&] () -> ParserStatus {
200200
auto element = parseType(diag::expected_type);

test/ASTGen/availability.swift

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,12 @@ func testSwift4OrLater() {}
3030
@available(macOS 12, iOS 13.1, *)
3131
func testShorthandMulti() {}
3232

33-
@available(macOS 12, iOS 13.1, *,)
34-
func testShorthandMulti2() {}
35-
3633
@available(macOS, unavailable)
3734
func testUnavailableMacOS() {}
3835

3936
@available(macOS, deprecated: 12.0.5, message: "whatever")
4037
func testDeprecaed12MacOS() {}
4138

42-
@available(
43-
macOS,
44-
deprecated: 12.0.5,
45-
message: "whatever",
46-
)
47-
func testDeprecaed12MacOS2() {}
48-
4939
@available(_iOS53Aligned, *)
5040
func testMacroNameOnly() {}
5141

@@ -58,27 +48,10 @@ func testSpecialize<T>(arg: T) -> T {}
5848
@backDeployed(before: _iOS53Aligned)
5949
public func testBackDeployed() {}
6050

61-
@backDeployed(
62-
before: _iOS53Aligned,
63-
)
64-
public func testBackDeployed2() {}
65-
6651
@available(macOS 10, iOS 12, *)
6752
@_originallyDefinedIn(module: "OriginalModule", macOS 12.0, iOS 23.2)
6853
public func testOriginallyDefinedIn() {}
6954

70-
@available(
71-
macOS 10,
72-
iOS 12,
73-
*,
74-
)
75-
@_originallyDefinedIn(
76-
module: "OriginalModule",
77-
macOS 12.0,
78-
iOS 23.2,
79-
)
80-
public func testOriginallyDefinedIn2() {}
81-
8255

8356
func testPoundIf() {
8457
if #available(_myProject 2.5, *) {

test/ASTGen/macros.swift

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ struct Outer {
1818
#anonymousTypes { "test" }
1919
}
2020

21-
@attached(
22-
extension,
23-
conformances: P1, P2,
24-
)
21+
@attached(extension, conformances: P1, P2)
2522
macro AddAllConformances() = #externalMacro(module: "MacroDefinition", type: "AddAllConformancesMacro")
2623

2724
protocol P1 {}
@@ -42,13 +39,6 @@ protocol DefaultInit {
4239
@attached(extension, conformances: Equatable, names: named(==))
4340
macro Equatable() = #externalMacro(module: "MacroDefinition", type: "EquatableViaMembersMacro")
4441

45-
@attached(
46-
extension,
47-
conformances: Equatable,
48-
names: named(==),
49-
)
50-
macro Equatable2() = #externalMacro(module: "MacroDefinition", type: "EquatableViaMembersMacro")
51-
5242
@propertyWrapper
5343
struct NotEquatable<T> {
5444
var wrappedValue: T
@@ -122,17 +112,10 @@ func remoteCall<Result: ConjureRemoteValue>(function: String, arguments: [String
122112
func f(a: Int, b: String) async throws -> String
123113

124114
@freestanding(declaration, names: arbitrary) macro bitwidthNumberedStructs(_ baseName: String) = #externalMacro(module: "MacroDefinition", type: "DefineBitwidthNumberedStructsMacro")
125-
126115
struct TestArbitrary {
127116
#bitwidthNumberedStructs("MyIntOne")
128117
}
129118
130-
@freestanding(
131-
declaration,
132-
names: arbitrary,
133-
)
134-
macro bitwidthNumberedStructs2(_ baseName: String) = #externalMacro(module: "MacroDefinition", type: "DefineBitwidthNumberedStructsMacro")
135-
136119
// Stored properties generated by a peer macro
137120
@attached(accessor)
138121
@attached(peer, names: prefixed(_))
@@ -168,8 +151,5 @@ protocol MyType {
168151
associatedtype Value
169152
associatedtype Entity
170153
}
171-
@attached(
172-
peer,
173-
names: named(bar),
174-
)
154+
@attached(peer, names: named(bar))
175155
macro Wrapper<Value>(get: (Value.Entity) async throws -> Value.Value) = #externalMacro(module: "MacroDefinition", type: "WrapperMacro") where Value: MyType

test/Parse/availability_query.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ if #available(OSX 51, iOS 8.0, *) {
9494
if #available(OSX 51, { // expected-error {{expected platform name}} // expected-error {{expected ')'}} expected-note {{to match this opening '('}}
9595
}
9696

97-
if #available(OSX 51,) { // expected-error {{must handle potential future platforms with '*'}}
97+
if #available(OSX 51,) { // expected-error {{expected platform name}}
9898
}
9999

100100
if #available(OSX 51, iOS { // expected-error {{expected ')'}} expected-note {{to match this opening '('}}

test/Parse/trailing-comma.swift

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ let values: [Int,] = [] // expected-note {{to match this opening '['}} expected-
99
// Tuple and Tuple Pattern
1010

1111
let _ = (a: 1, b: 2, c: 3,)
12+
let _: (a: Int, b: Int, c: Int,) = (a: 1, b: 2, c: 3,)
13+
14+
// Closures
15+
let _: (String, Int, Float,) -> Void
1216

1317
let (_, _,) = (0,1,)
1418

@@ -34,7 +38,7 @@ struct S<T1, T2,> { }
3438

3539
func foo<T1, T2,>() { }
3640

37-
protocol P<T1, T2> {
41+
protocol P<T1, T2,> {
3842
associatedtype T1
3943
associatedtype T2
4044
}
@@ -66,20 +70,20 @@ struct S {
6670

6771
if #unavailable(iOS 15, watchOS 9,) { }
6872

69-
if #available(iOS 15,) { }
73+
if #available(iOS 15,) { } // expected-error {{expected platform name}}
7074

7175
// Built-in Attributes
7276

73-
@attached(extension, conformances: OptionSet,)
77+
@attached(extension, conformances: OptionSet,) // expected-error {{unexpected ',' separator}}
7478
macro OptionSet<RawType>() = #externalMacro(module: "SwiftMacros", type: "OptionSetMacro")
7579

7680
@inline(never,) // expected-error {{expected declaration}} expected-error {{expected ')' in 'inline' attribute}}
7781
func foo() { }
7882

79-
@available(iOS 15,)
83+
@available(iOS 15,) // expected-error {{expected platform name}} expected-error {{expected declaration}}
8084
func foo() { }
8185

82-
@backDeployed(before: SwiftStdlib 6.0,)
86+
@backDeployed(before: SwiftStdlib 6.0,) // expected-error {{unexpected ',' separator}}
8387
func foo() { }
8488

8589
struct Foo {
@@ -88,7 +92,7 @@ struct Foo {
8892
var y: Int
8993

9094
var value: (Int, Int) {
91-
@storageRestrictions(initializes: x, y,)
95+
@storageRestrictions(initializes: x, y,) // expected-error {{expected property name in '@storageRestrictions' list}}
9296
init(initialValue) {
9397
self.x = initialValue.0
9498
self.y = initialValue.1
@@ -98,7 +102,7 @@ struct Foo {
98102

99103
}
100104

101-
func f(in: @differentiable(reverse,) (Int) -> Int) { } // expected-warning {{@differentiable' has been renamed to '@differentiable(reverse)' and will be removed in the next release}} expected-error {{expected ',' separator}} expected-error {{unnamed parameters must be written with the empty name '_'}}
105+
func f(in: @differentiable(reverse,) (Int) -> Int) { } // expected-warning {{@differentiable' has been renamed to '@differentiable(reverse)' and will be removed in the next release}} expected-error {{unexpected ',' separator}} expected-error {{expected ',' separator}} expected-error {{unnamed parameters must be written with the empty name '_'}}
102106

103107
@derivative(of: Self.other,) // expected-error {{unexpected ',' separator}}
104108
func foo() {}
@@ -135,4 +139,12 @@ if true, { } // expected-error {{expected '{' after 'if' condition}}
135139

136140
guard true, else { } // expected-error {{expected expression in conditional}}
137141

138-
while true, { } // expected-error {{expected '{' after 'while' condition}}
142+
while true, { } // expected-error {{expected '{' after 'while' condition}}
143+
144+
if #available(OSX 51,) { // expected-error {{expected platform name}}
145+
}
146+
147+
@available(OSX 10.7, iOS 7.0, *,) // expected-error {{expected platform name}}
148+
@_originallyDefinedIn(module: "HighLevel", OSX 10.9, iOS 13.0,) // expected-error {{unexpected ',' separator}}
149+
@backDeployed(before: OSX 10.9,) // expected-error {{expected version number in '@backDeployed' attribute}}
150+
public struct StructWithAvailability {}

test/attr/Inputs/SymbolMove/LowLevel.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,8 @@ extension Box {
3030
public func shape() -> String { return "round"}
3131
}
3232

33-
@available(
34-
OSX 10.7,
35-
iOS 7.0,
36-
*,
37-
)
38-
@_originallyDefinedIn(
39-
module: "HighLevel",
40-
OSX 10.9,
41-
iOS 13.0,
42-
)
33+
@available(OSX 10.7, iOS 7.0, *)
34+
@_originallyDefinedIn(module: "HighLevel", OSX 10.9, iOS 13.0)
4335
public struct Candy {
4436
public var kind = "candy"
4537
public init() {}

test/attr/attr_availability_noasync.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,9 @@
66
@available(*, noasync)
77
func basicNoAsync() { }
88

9-
@available(*, noasync,)
10-
func basicNoAsync2() { }
11-
129
@available(*, noasync, message: "a message from the author")
1310
func messageNoAsync() { }
1411

15-
@available(
16-
*,
17-
noasync,
18-
message: "a message from the author",
19-
)
20-
func messageNoAsync2() { }
21-
2212
@available(*, noasync, renamed: "asyncReplacement()")
2313
func renamedNoAsync(_ completion: @escaping (Int) -> Void) -> Void { }
2414

test/attr/attr_availability_watchos.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ if #available(
6363
watchOS 2.1,
6464
*,
6565
) {
66-
functionIntroducedOnwatchOS2_2() // expected-error {{'functionIntroducedOnwatchOS2_2()' is only available in watchOS 2.2 or newer}} {{63:11-14=2.2}}
66+
functionIntroducedOnwatchOS2_2() // expected-error {{'functionIntroducedOnwatchOS2_2()' is only available in watchOS 2.2 or newer}} {{-1:32-35=2.2}}
6767
}
6868

6969
if #available(iOS 9.1, watchOS 2.2, *) {

test/attr/attr_backDeployed.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ public func missingVersionFunc3() {}
394394
@backDeployed(before: macOS 0) // expected-warning {{expected version number in '@backDeployed' attribute; this is an error in the Swift 6 language mode}}
395395
public func missingVersionFunc4() {}
396396

397-
@backDeployed(before: macOS 12.0, iOS 15.0,)
398-
public func trailingCommaFunc1() {}
397+
@backDeployed(before: macOS 12.0, iOS 15.0,) // expected-error {{unexpected ',' separator}}
398+
public func unexpectedSeparatorFunc() {}
399399

400400
@backDeployed(before: macOS 12.0.1) // expected-warning {{'@backDeployed' only uses major and minor version number}}
401401
public func patchVersionFunc() {}
@@ -440,8 +440,8 @@ public func missingColonAfterBeforeFunc() {}
440440
@backDeployed(before macOS 12.0) // expected-error {{expected ':' after 'before' in '@backDeployed' attribute}} {{21-21=:}}
441441
public func missingColonBetweenBeforeAndPlatformFunc() {}
442442

443-
@backDeployed(before: macOS 12.0,)
444-
public func trailingCommaFunc2() {}
443+
@backDeployed(before: macOS 12.0,) // expected-error {{unexpected ',' separator}} {{33-34=}}
444+
public func unexpectedTrailingCommaFunc() {}
445445

446446
@backDeployed(before: macOS 12.0,, iOS 15.0) // expected-error {{unexpected ',' separator}} {{34-35=}}
447447
public func extraCommaFunc() {}

test/attr/attr_inlinable_available.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,7 @@ public func spiDeployedUseNoAvailable( // expected-note 3 {{add '@available' att
530530
_ = AtDeploymentTarget()
531531
_ = AfterDeploymentTarget() // expected-error {{'AfterDeploymentTarget' is only available in macOS 11 or newer}} expected-note {{add 'if #available'}}
532532

533-
if #available(
534-
macOS 11,
535-
*,
536-
) {
533+
if #available(macOS 11, *) {
537534
_ = AfterDeploymentTarget()
538535
}
539536
}
@@ -723,7 +720,7 @@ public func spiDeployedUseNoAvailable( // expected-note 3 {{add '@available' att
723720
_ = AtDeploymentTarget()
724721
_ = AfterDeploymentTarget()
725722

726-
if #available(macOS 11, *,) {
723+
if #available(macOS 11, *) {
727724
_ = AfterDeploymentTarget()
728725
}
729726

test/decl/var/init_accessors.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ func test_use_of_initializes_accesses_on_non_inits() {
4545
var y: String
4646

4747
var _x: Int {
48-
@storageRestrictions(
49-
initializes: x,
50-
accesses: y,
51-
)
48+
@storageRestrictions(initializes: x, accesses: y)
5249
init(initialValue) { // Ok
5350
}
5451

0 commit comments

Comments
 (0)