@@ -1531,7 +1531,8 @@ final class DeclarationTests: ParserTestCase {
15311531 leftSquare: . leftSquareToken( ) ,
15321532 element: IdentifierTypeSyntax ( name: . identifier( " third " ) ) ,
15331533 rightSquare: . rightSquareToken( presence: . missing)
1534- )
1534+ ) ,
1535+ trailingComma: . commaToken( presence: . missing)
15351536 ) ,
15361537 diagnostics: [
15371538 DiagnosticSpec (
@@ -1547,11 +1548,12 @@ final class DeclarationTests: ParserTestCase {
15471548 ) ,
15481549 DiagnosticSpec (
15491550 locationMarker: " 4️⃣ " ,
1550- message: " unexpected code 'fourth: Int' in parameter clause "
1551+ message: " expected ',' in parameter " ,
1552+ fixIts: [ " insert ',' " ]
15511553 ) ,
15521554 ] ,
15531555 fixedSource: """
1554- func foo(first second: [third]fourth: Int) {}
1556+ func foo(first second: [third], fourth: Int) {}
15551557 """
15561558 )
15571559 }
@@ -3417,4 +3419,85 @@ final class DeclarationTests: ParserTestCase {
34173419 ]
34183420 )
34193421 }
3422+
3423+ func testMissingCommaInParameters( ) {
3424+ assertParse (
3425+ " func a(foo: Bar1️⃣ foo2: Bar2) {} " ,
3426+ diagnostics: [
3427+ DiagnosticSpec (
3428+ message: " expected ',' in parameter " ,
3429+ fixIts: [ " insert ',' " ]
3430+ )
3431+ ] ,
3432+ fixedSource: " func a(foo: Bar, foo2: Bar2) {} "
3433+ )
3434+ }
3435+
3436+ func testMissingMultipleCommasInParameters( ) {
3437+ assertParse (
3438+ " func a(foo: Bar1️⃣ foo2: Bar2, foo3: Bar32️⃣ foo4: Bar4) {} " ,
3439+ diagnostics: [
3440+ DiagnosticSpec (
3441+ locationMarker: " 1️⃣ " ,
3442+ message: " expected ',' in parameter " ,
3443+ fixIts: [ " insert ',' " ]
3444+ ) ,
3445+ DiagnosticSpec (
3446+ locationMarker: " 2️⃣ " ,
3447+ message: " expected ',' in parameter " ,
3448+ fixIts: [ " insert ',' " ]
3449+ ) ,
3450+ ] ,
3451+ fixedSource: " func a(foo: Bar, foo2: Bar2, foo3: Bar3, foo4: Bar4) {} "
3452+ )
3453+ }
3454+
3455+ func testMissingCommaInParametersAndAttributes( ) {
3456+ assertParse (
3457+ " func a(foo: Bar1️⃣ @escaping foo1: () -> Void) {} " ,
3458+ diagnostics: [
3459+ DiagnosticSpec (
3460+ locationMarker: " 1️⃣ " ,
3461+ message: " expected ',' in parameter " ,
3462+ fixIts: [ " insert ',' " ]
3463+ )
3464+ ] ,
3465+ fixedSource: " func a(foo: Bar, @escaping foo1: () -> Void) {} "
3466+ )
3467+ }
3468+
3469+ func testMissingCommaInParametersWithNewline( ) {
3470+ assertParse (
3471+ """
3472+ func foo(a: Int1️⃣
3473+ x: Int = 2
3474+ ) {}
3475+ """ ,
3476+ diagnostics: [
3477+ DiagnosticSpec (
3478+ locationMarker: " 1️⃣ " ,
3479+ message: " expected ',' in parameter " ,
3480+ fixIts: [ " insert ',' " ]
3481+ )
3482+ ] ,
3483+ fixedSource:
3484+ """
3485+ func foo(a: Int,
3486+ x: Int = 2
3487+ ) {}
3488+ """
3489+ )
3490+ }
3491+
3492+ func testMissingCommaWithgarbageCode( ) {
3493+ assertParse (
3494+ " func foo(x: Int 1️⃣Int<@abc) " ,
3495+ diagnostics: [
3496+ DiagnosticSpec (
3497+ locationMarker: " 1️⃣ " ,
3498+ message: " unexpected code 'Int<@abc' in parameter clause "
3499+ )
3500+ ]
3501+ )
3502+ }
34203503}
0 commit comments