Skip to content

Commit 9a3f33d

Browse files
committed
Support trailing commas in types within expressions
1 parent 9072d86 commit 9a3f33d

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

lib/Parse/ParseType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,8 @@ bool Parser::canParseGenericArguments() {
16091609
if (!canParseType())
16101610
return false;
16111611
// Parse the comma, if the list continues.
1612-
} while (consumeIf(tok::comma));
1612+
// This could be the trailing comma.
1613+
} while (consumeIf(tok::comma) && !startsWithGreater(Tok));
16131614

16141615
if (!startsWithGreater(Tok)) {
16151616
return false;

test/Parse/trailing-comma.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ struct Foo {
102102

103103
}
104104

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 '_'}}
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 {{expected ',' separator}} expected-error {{unnamed parameters must be written with the empty name '_'}}
106106

107107
@derivative(of: Self.other,) // expected-error {{unexpected ',' separator}}
108108
func foo() {}
@@ -144,7 +144,7 @@ while true, { } // expected-error {{expected '{' after 'while' condition}}
144144
if #available(OSX 51,) { // expected-error {{expected platform name}}
145145
}
146146

147-
@available(OSX 10.7, iOS 7.0, *,) // expected-error {{expected platform name}}
147+
@available(OSX 10.7, iOS 7.0, *,) // expected-error {{expected platform name}} expected-error {{expected declaration}}
148148
@_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}}
149+
@backDeployed(before: OSX 10.9,) // expected-error {{unexpected ',' separator}}
150150
public struct StructWithAvailability {}

test/decl/ext/typealias.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,6 @@ typealias Bar2<
8888
T2,
8989
Bool,
9090
>
91+
92+
let _ = Foo2<Int, Bool, String,>.self
93+
let _ = Bar2<Int, Bool,>()

test/type/types.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ let tupleTypeWithTrailingComma: (
225225
quux: String,
226226
)
227227

228+
let _ = (bar: String, quux: String,).self
229+
228230
let closureTypeWithTrailingCommas: (
229231
String,
230232
String,

0 commit comments

Comments
 (0)