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 {
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 @@ -331,7 +331,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
331
331
} else if node. first? . as ( TokenSyntax . self) ? . tokenKind. isIdentifier == true ,
332
332
let previousToken = node. previousToken ( viewMode: . sourceAccurate) ,
333
333
previousToken. tokenKind. isIdentifier,
334
- previousToken. parent? . is ( DeclSyntax . self) == true
334
+ previousToken. parent? . is ( DeclSyntax . self) == true || previousToken . parent ? . is ( IdentifierPatternSyntax . self ) == true
335
335
{
336
336
// If multiple identifiers are used for a declaration name, offer to join them together.
337
337
let tokens =
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,24 @@ final class RecoveryTests: XCTestCase {
828
828
) ,
829
829
DiagnosticSpec (
830
830
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 " ]
833
833
) ,
834
- DiagnosticSpec ( locationMarker: " 3️⃣ " , message: #"unexpected code ': Int = ""' before function"# ) ,
835
834
DiagnosticSpec (
836
- locationMarker: " 4️⃣ " ,
835
+ locationMarker: " 3️⃣ " ,
837
836
message: " expected ':' in type annotation " ,
838
837
fixIts: [ " insert ':' " ]
839
838
) ,
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
+ """#
841
849
)
842
850
}
843
851
@@ -869,6 +877,24 @@ final class RecoveryTests: XCTestCase {
869
877
)
870
878
}
871
879
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
+
872
898
func testRecovery65( ) {
873
899
assertParse (
874
900
"""
You can’t perform that action at this time.
0 commit comments