File tree Expand file tree Collapse file tree 3 files changed +39
-11
lines changed
Tests/SwiftParserTest/translated Expand file tree Collapse file tree 3 files changed +39
-11
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 @@ -331,7 +331,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
331331 } else if node. first? . as ( TokenSyntax . self) ? . tokenKind. isIdentifier == true ,
332332 let previousToken = node. previousToken ( viewMode: . sourceAccurate) ,
333333 previousToken. tokenKind. isIdentifier,
334- previousToken. parent? . is ( DeclSyntax . self) == true
334+ previousToken. parent? . is ( DeclSyntax . self) == true || previousToken . parent ? . is ( IdentifierPatternSyntax . self ) == true
335335 {
336336 // If multiple identifiers are used for a declaration name, offer to join them together.
337337 let tokens =
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,24 @@ final class RecoveryTests: XCTestCase {
828828 ) ,
829829 DiagnosticSpec (
830830 locationMarker: " 2️⃣ " ,
831- message: " expected ':' in type annotation " ,
832- fixIts: [ " insert ':' " ]
831+ message: " found an unexpected second identifier in pattern; is there an accidental break? " ,
832+ fixIts: [ " join the identifiers together " , " join the identifiers together with camel-case " ]
833833 ) ,
834- DiagnosticSpec ( locationMarker: " 3️⃣ " , message: #"unexpected code ': Int = ""' before function"# ) ,
835834 DiagnosticSpec (
836- locationMarker: " 4️⃣ " ,
835+ locationMarker: " 3️⃣ " ,
837836 message: " expected ':' in type annotation " ,
838837 fixIts: [ " insert ':' " ]
839838 ) ,
840- ]
839+ ] ,
840+ fixedSource: #"""
841+ struct SSSS : Multi {
842+ private var ab : Int = ""
843+ func f() {
844+ var c: d = 5
845+ let _ = 0
846+ }
847+ }
848+ """#
841849 )
842850 }
843851
@@ -869,6 +877,24 @@ final class RecoveryTests: XCTestCase {
869877 )
870878 }
871879
880+ func testRecovery64c( ) {
881+ assertParse (
882+ """
883+ private var a 1️⃣b : Int = " "
884+ """ ,
885+ diagnostics: [
886+ DiagnosticSpec (
887+ locationMarker: " 1️⃣ " ,
888+ message: " found an unexpected second identifier in pattern; is there an accidental break? " ,
889+ fixIts: [ " join the identifiers together " , " join the identifiers together with camel-case " ]
890+ )
891+ ] ,
892+ fixedSource: """
893+ private var ab : Int = " "
894+ """
895+ )
896+ }
897+
872898 func testRecovery65( ) {
873899 assertParse (
874900 """
You can’t perform that action at this time.
0 commit comments