File tree Expand file tree Collapse file tree 2 files changed +34
-7
lines changed
Tests/SwiftParserTest/translated Expand file tree Collapse file tree 2 files changed +34
-7
lines changed Original file line number Diff line number Diff line change @@ -1057,20 +1057,23 @@ extension Parser {
1057
1057
return result
1058
1058
}
1059
1059
1060
- if self . at ( . rightSquareBracket) {
1061
- let ( unexpectedBeforeRSquareBracket, rightSquareBracket) = self . expect ( . rightSquareBracket)
1060
+ var lookahead = self . lookahead ( )
1061
+
1062
+ // If we are at a new line, we cannot assume it's an unfinished dictionary or array.
1063
+ if lookahead. currentToken. isAtStartOfLine {
1064
+ return result
1065
+ }
1066
+
1067
+ if let rightSquareBracket = self . consume ( if: . rightSquareBracket) {
1062
1068
result = RawTypeSyntax (
1063
1069
RawArrayTypeSyntax (
1064
1070
leftSquareBracket: missingToken ( . leftSquareBracket) ,
1065
1071
elementType: result,
1066
- unexpectedBeforeRSquareBracket,
1067
1072
rightSquareBracket: rightSquareBracket,
1068
1073
arena: self . arena
1069
1074
)
1070
1075
)
1071
1076
} else if self . at ( . colon) {
1072
- var lookahead = self . lookahead ( )
1073
-
1074
1077
// We only want to continue with a dictionary if we can parse a colon and a simpletype.
1075
1078
// Otherwise we can get a wrong diagnostic if we get a Python-style function declaration.
1076
1079
guard lookahead. consume ( if: . colon) != nil && lookahead. canParseSimpleType ( ) else {
Original file line number Diff line number Diff line change @@ -1498,6 +1498,18 @@ final class RecoveryTests: XCTestCase {
1498
1498
line: line
1499
1499
)
1500
1500
}
1501
+
1502
+ assertParse (
1503
+ """
1504
+ let a8: Int
1505
+ 1️⃣]
1506
+ """ ,
1507
+ diagnostics: [
1508
+ DiagnosticSpec (
1509
+ message: " extraneous code ']' at top level "
1510
+ )
1511
+ ]
1512
+ )
1501
1513
}
1502
1514
1503
1515
func testRecovery98b( ) {
@@ -1527,7 +1539,7 @@ final class RecoveryTests: XCTestCase {
1527
1539
let a2: 2️⃣String: Int]
1528
1540
let a3: 3️⃣String: [Int]4️⃣
1529
1541
let a4: 5️⃣String: Int6️⃣
1530
- let a4 : 7️⃣String: Int]??
1542
+ let a5 : 7️⃣String: Int]??
1531
1543
}
1532
1544
""" ,
1533
1545
diagnostics: [
@@ -1577,10 +1589,22 @@ final class RecoveryTests: XCTestCase {
1577
1589
let a2: [String: Int]
1578
1590
let a3: [String: [Int]]
1579
1591
let a4: [String: Int]
1580
- let a4 : [String: Int]??
1592
+ let a5 : [String: Int]??
1581
1593
}
1582
1594
"""
1583
1595
)
1596
+
1597
+ assertParse (
1598
+ """
1599
+ let a6: [Int: String]
1600
+ 1️⃣]
1601
+ """ ,
1602
+ diagnostics: [
1603
+ DiagnosticSpec (
1604
+ message: " extraneous code ']' at top level "
1605
+ )
1606
+ ]
1607
+ )
1584
1608
}
1585
1609
1586
1610
func testRecovery100( ) {
You can’t perform that action at this time.
0 commit comments