File tree Expand file tree Collapse file tree 2 files changed +37
-10
lines changed
Tests/SwiftParserTest/translated Expand file tree Collapse file tree 2 files changed +37
-10
lines changed Original file line number Diff line number Diff line change @@ -175,10 +175,12 @@ extension Parser {
175
175
&& !self . currentToken. isAtStartOfLine
176
176
&& lookahead. canParseType ( )
177
177
{
178
- // Recovery if the user forgot to add ':'
179
- let result = self . parseResultType ( )
178
+ let ( unexpectedBeforeColon, colon) = self . expect ( . colon)
179
+ let result = self . parseType ( )
180
+
180
181
type = RawTypeAnnotationSyntax (
181
- colon: self . missingToken ( . colon) ,
182
+ unexpectedBeforeColon,
183
+ colon: colon,
182
184
type: result,
183
185
arena: self . arena
184
186
)
Original file line number Diff line number Diff line change @@ -813,9 +813,9 @@ final class RecoveryTests: XCTestCase {
813
813
assertParse (
814
814
#"""
815
815
struct SS 1️⃣SS : Multi {
816
- private var a 2️⃣b 3️⃣ : Int = ""
816
+ private var a 2️⃣b : Int = ""
817
817
func f() {
818
- var c 4️⃣d = 5
818
+ var c 3️⃣d = 5
819
819
let _ = 0
820
820
}
821
821
}
@@ -828,16 +828,23 @@ final class RecoveryTests: XCTestCase {
828
828
) ,
829
829
DiagnosticSpec (
830
830
locationMarker: " 2️⃣ " ,
831
- message: " expected ':' in type annotation " ,
832
- fixIts: [ " insert ':' " ]
831
+ message: " unexpected code 'b' before type annotation "
833
832
) ,
834
- DiagnosticSpec ( locationMarker: " 3️⃣ " , message: #"unexpected code ': Int = ""' before function"# ) ,
835
833
DiagnosticSpec (
836
- locationMarker: " 4️⃣ " ,
834
+ locationMarker: " 3️⃣ " ,
837
835
message: " expected ':' in type annotation " ,
838
836
fixIts: [ " insert ':' " ]
839
837
) ,
840
- ]
838
+ ] ,
839
+ fixedSource: #"""
840
+ struct SSSS : Multi {
841
+ private var a b : Int = ""
842
+ func f() {
843
+ var c: d = 5
844
+ let _ = 0
845
+ }
846
+ }
847
+ """#
841
848
)
842
849
}
843
850
@@ -869,6 +876,24 @@ final class RecoveryTests: XCTestCase {
869
876
)
870
877
}
871
878
879
+ func testRecovery64c( ) {
880
+ assertParse (
881
+ """
882
+ private var a 1️⃣b : Int = " "
883
+ """ ,
884
+ diagnostics: [
885
+ DiagnosticSpec (
886
+ locationMarker: " 1️⃣ " ,
887
+ message: " found an unexpected second identifier in struct; is there an accidental break? " ,
888
+ fixIts: [ " join the identifiers together " ]
889
+ )
890
+ ] ,
891
+ fixedSource: """
892
+ private var ab : Int = " "
893
+ """
894
+ )
895
+ }
896
+
872
897
func testRecovery65( ) {
873
898
assertParse (
874
899
"""
You can’t perform that action at this time.
0 commit comments