Support trailing commas in types within expressions

This commit is contained in:
Cal Stephens
2025-05-19 18:36:58 -07:00
parent f4bedbc720
commit e73beb435e
4 changed files with 10 additions and 4 deletions

View File

@@ -1609,7 +1609,8 @@ bool Parser::canParseGenericArguments() {
if (!canParseType())
return false;
// Parse the comma, if the list continues.
} while (consumeIf(tok::comma));
// This could be the trailing comma.
} while (consumeIf(tok::comma) && !startsWithGreater(Tok));
if (!startsWithGreater(Tok)) {
return false;

View File

@@ -102,7 +102,7 @@ struct Foo {
}
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 '_'}}
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 '_'}}
@derivative(of: Self.other,) // expected-error {{unexpected ',' separator}}
func foo() {}
@@ -144,7 +144,7 @@ while true, { } // expected-error {{expected '{' after 'while' condition}}
if #available(OSX 51,) { // expected-error {{expected platform name}}
}
@available(OSX 10.7, iOS 7.0, *,) // expected-error {{expected platform name}}
@available(OSX 10.7, iOS 7.0, *,) // expected-error {{expected platform name}} expected-error {{expected declaration}}
@_originallyDefinedIn(module: "HighLevel", OSX 10.9, iOS 13.0,) // expected-error {{unexpected ',' separator}}
@backDeployed(before: OSX 10.9,) // expected-error {{expected version number in '@backDeployed' attribute}}
@backDeployed(before: OSX 10.9,) // expected-error {{unexpected ',' separator}}
public struct StructWithAvailability {}

View File

@@ -88,3 +88,6 @@ typealias Bar2<
T2,
Bool,
>
let _ = Foo2<Int, Bool, String,>.self
let _ = Bar2<Int, Bool,>()

View File

@@ -225,6 +225,8 @@ let tupleTypeWithTrailingComma: (
quux: String,
)
let _ = (bar: String, quux: String,).self
let closureTypeWithTrailingCommas: (
String,
String,