File tree Expand file tree Collapse file tree 2 files changed +36
-10
lines changed
Tests/SwiftParserTest/translated Expand file tree Collapse file tree 2 files changed +36
-10
lines changed Original file line number Diff line number Diff line change @@ -175,10 +175,12 @@ extension Parser {
175175 && !self . currentToken. isAtStartOfLine
176176 && lookahead. canParseType ( )
177177 {
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+
180181 type = RawTypeAnnotationSyntax (
181- colon: self . missingToken ( . colon) ,
182+ unexpectedBeforeColon,
183+ colon: colon,
182184 type: result,
183185 arena: self . arena
184186 )
Original file line number Diff line number Diff line change @@ -813,9 +813,9 @@ final class RecoveryTests: XCTestCase {
813813 assertParse (
814814 #"""
815815 struct SS 1️⃣SS : Multi {
816- private var a 2️⃣b 3️⃣ : Int = ""
816+ private var a 2️⃣b : Int = ""
817817 func f() {
818- var c 4️⃣d = 5
818+ var c 3️⃣d = 5
819819 let _ = 0
820820 }
821821 }
@@ -828,16 +828,23 @@ final class RecoveryTests: XCTestCase {
828828 ) ,
829829 DiagnosticSpec (
830830 locationMarker: " 2️⃣ " ,
831- message: " expected ':' in type annotation " ,
832- fixIts: [ " insert ':' " ]
831+ message: " unexpected code 'b' before type annotation "
833832 ) ,
834- DiagnosticSpec ( locationMarker: " 3️⃣ " , message: #"unexpected code ': Int = ""' before function"# ) ,
835833 DiagnosticSpec (
836- locationMarker: " 4️⃣ " ,
834+ locationMarker: " 3️⃣ " ,
837835 message: " expected ':' in type annotation " ,
838836 fixIts: [ " insert ':' " ]
839837 ) ,
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+ """#
841848 )
842849 }
843850
@@ -869,6 +876,23 @@ final class RecoveryTests: XCTestCase {
869876 )
870877 }
871878
879+ func testRecovery64c( ) {
880+ assertParse (
881+ """
882+ private var a 1️⃣b : Int = " "
883+ """ ,
884+ diagnostics: [
885+ DiagnosticSpec (
886+ locationMarker: " 1️⃣ " ,
887+ message: " unexpected code 'b' before type annotation "
888+ )
889+ ] ,
890+ fixedSource: """
891+ private var a b : Int = " "
892+ """
893+ )
894+ }
895+
872896 func testRecovery65( ) {
873897 assertParse (
874898 """
You can’t perform that action at this time.
0 commit comments