@@ -1838,44 +1838,31 @@ final class RecoveryTests: ParserTestCase {
1838
1838
func testRecovery100( ) {
1839
1839
assertParse (
1840
1840
"""
1841
- struct ErrorInFunctionSignatureResultArrayType1 1️⃣ {
1842
- func foo() -> Int2️⃣ [ {
1841
+ struct ErrorInFunctionSignatureResultArrayType1 {
1842
+ func foo() -> Int1️⃣ [ {
1843
1843
return [0]
1844
- }3️⃣
1845
- func bar() -> Int4️⃣ ] {
1844
+ }
1845
+ func bar() -> Int2️⃣ ] {
1846
1846
return [0]
1847
1847
}
1848
- 5️⃣ }
1848
+ }
1849
1849
""" ,
1850
1850
diagnostics: [
1851
1851
DiagnosticSpec (
1852
- locationMarker: " 2️⃣ " ,
1853
- message: " expected '}' to end struct " ,
1854
- notes: [ NoteSpec ( locationMarker: " 1️⃣ " , message: " to match this opening '{' " ) ] ,
1855
- fixIts: [ " insert '}' " ]
1856
- ) ,
1857
- DiagnosticSpec (
1858
- locationMarker: " 3️⃣ " ,
1859
- message: " expected ']' to end array " ,
1860
- notes: [ NoteSpec ( locationMarker: " 2️⃣ " , message: " to match this opening '[' " ) ] ,
1861
- fixIts: [ " insert ']' " ]
1852
+ locationMarker: " 1️⃣ " ,
1853
+ message: " unexpected code '[' in function "
1862
1854
) ,
1863
1855
DiagnosticSpec (
1864
- locationMarker: " 4️⃣ " ,
1856
+ locationMarker: " 2️⃣ " ,
1865
1857
message: " unexpected ']' in type; did you mean to write an array type? " ,
1866
1858
fixIts: [ " insert '[' " ]
1867
1859
) ,
1868
- DiagnosticSpec (
1869
- locationMarker: " 5️⃣ " ,
1870
- message: " extraneous brace at top level "
1871
- ) ,
1872
1860
] ,
1873
1861
fixedSource: """
1874
1862
struct ErrorInFunctionSignatureResultArrayType1 {
1875
- func foo() -> Int
1876
- }[ {
1863
+ func foo() -> Int[ {
1877
1864
return [0]
1878
- }]
1865
+ }
1879
1866
func bar() -> [Int] {
1880
1867
return [0]
1881
1868
}
@@ -1887,45 +1874,15 @@ final class RecoveryTests: ParserTestCase {
1887
1874
func testRecovery101( ) {
1888
1875
assertParse (
1889
1876
"""
1890
- struct ErrorInFunctionSignatureResultArrayType2 1️⃣ {
1891
- func foo() -> Int2️⃣[03️⃣ {
1877
+ struct ErrorInFunctionSignatureResultArrayType2 {
1878
+ func foo() -> Int1️⃣[0 {
1892
1879
return [0]
1893
- }4️⃣
1894
- 5️⃣ }
1880
+ }
1881
+ }
1895
1882
""" ,
1896
1883
diagnostics: [
1897
- // TODO: Old parser expected error to add `]` on line 2, but we should just recover to
1898
- // `{` with `[0` becoming unexpected.
1899
- DiagnosticSpec (
1900
- locationMarker: " 2️⃣ " ,
1901
- message: " expected '}' to end struct " ,
1902
- notes: [ NoteSpec ( locationMarker: " 1️⃣ " , message: " to match this opening '{' " ) ] ,
1903
- fixIts: [ " insert '}' " ]
1904
- ) ,
1905
- DiagnosticSpec (
1906
- locationMarker: " 3️⃣ " ,
1907
- message: " expected ',' in array element " ,
1908
- fixIts: [ " insert ',' " ]
1909
- ) ,
1910
- DiagnosticSpec (
1911
- locationMarker: " 4️⃣ " ,
1912
- message: " expected ']' to end array " ,
1913
- notes: [ NoteSpec ( locationMarker: " 2️⃣ " , message: " to match this opening '[' " ) ] ,
1914
- fixIts: [ " insert ']' " ]
1915
- ) ,
1916
- DiagnosticSpec (
1917
- locationMarker: " 5️⃣ " ,
1918
- message: " extraneous brace at top level "
1919
- ) ,
1920
- ] ,
1921
- fixedSource: """
1922
- struct ErrorInFunctionSignatureResultArrayType2 {
1923
- func foo() -> Int
1924
- }[0, {
1925
- return [0]
1926
- }]
1927
- }
1928
- """
1884
+ DiagnosticSpec ( message: " unexpected code '[0' in function " )
1885
+ ]
1929
1886
)
1930
1887
}
1931
1888
@@ -1977,37 +1934,14 @@ final class RecoveryTests: ParserTestCase {
1977
1934
func testRecovery105( ) {
1978
1935
assertParse (
1979
1936
"""
1980
- struct ErrorInFunctionSignatureResultArrayType11 ℹ️ {
1981
- func foo() -> Int1️⃣[(a){a++}]2️⃣ {
1937
+ struct ErrorInFunctionSignatureResultArrayType11 {
1938
+ func foo() -> Int1️⃣[(a){a++}] {
1982
1939
}
1983
- 3️⃣ }
1940
+ }
1984
1941
""" ,
1985
1942
diagnostics: [
1986
- // TODO: We should just recover to `{` with `[(a){a++}]` becoming unexpected.
1987
- DiagnosticSpec (
1988
- locationMarker: " 1️⃣ " ,
1989
- message: " expected '}' to end struct " ,
1990
- notes: [ NoteSpec ( message: " to match this opening '{' " ) ] ,
1991
- fixIts: [ " insert '}' " ]
1992
- ) ,
1993
- DiagnosticSpec (
1994
- locationMarker: " 2️⃣ " ,
1995
- message: " consecutive statements on a line must be separated by newline or ';' " ,
1996
- fixIts: [ " insert newline " , " insert ';' " ]
1997
- ) ,
1998
- DiagnosticSpec (
1999
- locationMarker: " 3️⃣ " ,
2000
- message: " extraneous brace at top level "
2001
- ) ,
2002
- ] ,
2003
- fixedSource: """
2004
- struct ErrorInFunctionSignatureResultArrayType11 {
2005
- func foo() -> Int
2006
- }[(a){a++}]
2007
- {
2008
- }
2009
- }
2010
- """
1943
+ DiagnosticSpec ( message: " unexpected code '[(a){a++}]' in function " )
1944
+ ]
2011
1945
)
2012
1946
}
2013
1947
@@ -2513,50 +2447,32 @@ final class RecoveryTests: ParserTestCase {
2513
2447
assertParse (
2514
2448
"""
2515
2449
#if true
2516
- struct Foo19605164 1️⃣ {
2517
- func a2️⃣ (s: S3️⃣ [{{g4️⃣) -> Int {}
2518
- }}5️⃣ }
2450
+ struct Foo19605164 {
2451
+ func a1️⃣ (s: S2️⃣3️⃣ [{{g4️⃣) -> Int {}
2452
+ }}}
2519
2453
#endif
2520
2454
""" ,
2521
2455
diagnostics: [
2522
2456
DiagnosticSpec (
2523
- locationMarker: " 3️⃣ " ,
2457
+ locationMarker: " 2️⃣ " ,
2524
2458
message: " expected ')' to end parameter clause " ,
2525
- notes: [ NoteSpec ( locationMarker: " 2️⃣ " , message: " to match this opening '(' " ) ] ,
2459
+ notes: [ NoteSpec ( locationMarker: " 1️⃣ " , message: " to match this opening '(' " ) ] ,
2526
2460
fixIts: [ " insert ')' " ]
2527
2461
) ,
2528
2462
DiagnosticSpec (
2529
2463
locationMarker: " 3️⃣ " ,
2530
- message: " expected '}' to end struct " ,
2531
- notes: [ NoteSpec ( locationMarker: " 1️⃣ " , message: " to match this opening '{' " ) ] ,
2532
- fixIts: [ " insert '}' " ]
2464
+ message: " unexpected code '[' in function "
2533
2465
) ,
2534
2466
DiagnosticSpec (
2535
2467
locationMarker: " 4️⃣ " ,
2536
2468
message: " unexpected code ') -> Int {}' in closure "
2537
2469
) ,
2538
- DiagnosticSpec (
2539
- locationMarker: " 5️⃣ " ,
2540
- message: " expected ',' in array element " ,
2541
- fixIts: [ " insert ',' " ]
2542
- ) ,
2543
- DiagnosticSpec (
2544
- locationMarker: " 5️⃣ " ,
2545
- message: " expected ']' to end array " ,
2546
- notes: [ NoteSpec ( locationMarker: " 3️⃣ " , message: " to match this opening '[' " ) ] ,
2547
- fixIts: [ " insert ']' " ]
2548
- ) ,
2549
- DiagnosticSpec (
2550
- locationMarker: " 5️⃣ " ,
2551
- message: " unexpected brace in conditional compilation block "
2552
- ) ,
2553
2470
] ,
2554
2471
fixedSource: """
2555
2472
#if true
2556
2473
struct Foo19605164 {
2557
- func a(s: S)
2558
- }[{{g) -> Int {}
2559
- }},]}
2474
+ func a(s: S) [{{g) -> Int {}
2475
+ }}}
2560
2476
#endif
2561
2477
"""
2562
2478
)
@@ -3211,28 +3127,13 @@ final class RecoveryTests: ParserTestCase {
3211
3127
func testRecovery179( ) {
3212
3128
assertParse (
3213
3129
"""
3214
- func testSkipUnbalancedParen() ℹ️{1️⃣
3215
- 2️⃣ ?(
3130
+ func testSkipUnbalancedParen() {
3131
+ 1️⃣ ?(
3216
3132
}
3217
3133
""" ,
3218
3134
diagnostics: [
3219
- DiagnosticSpec (
3220
- locationMarker: " 1️⃣ " ,
3221
- message: " expected '}' to end function " ,
3222
- notes: [ NoteSpec ( message: " to match this opening '{' " ) ] ,
3223
- fixIts: [ " insert '}' " ]
3224
- ) ,
3225
- DiagnosticSpec (
3226
- locationMarker: " 2️⃣ " ,
3227
- message: " extraneous code at top level "
3228
- ) ,
3229
- ] ,
3230
- fixedSource: """
3231
- func testSkipUnbalancedParen() {
3232
- }
3233
- ?(
3234
- }
3235
- """
3135
+ DiagnosticSpec ( message: " unexpected code '?(' in function " )
3136
+ ]
3236
3137
)
3237
3138
}
3238
3139
0 commit comments