File tree 2 files changed +40
-4
lines changed
Tests/SwiftParserTest/translated 2 files changed +40
-4
lines changed Original file line number Diff line number Diff line change @@ -316,10 +316,7 @@ extension Parser {
316
316
)
317
317
318
318
let rhs : RawExprSyntax ?
319
- if colon. isMissing {
320
- // If the colon is missing there's not much more structure we can
321
- // expect out of this expression sequence. Emit a missing expression
322
- // to end the parsing here.
319
+ if colon. isMissing, currentToken. isAtStartOfLine {
323
320
rhs = RawExprSyntax ( RawMissingExprSyntax ( arena: self . arena) )
324
321
} else {
325
322
rhs = nil
Original file line number Diff line number Diff line change @@ -69,4 +69,43 @@ final class InvalidIfExprTests: XCTestCase {
69
69
)
70
70
}
71
71
72
+ func testInvalidIfExpr5( ) {
73
+ assertParse (
74
+ """
75
+ foo ? 1 1️⃣2
76
+ """ ,
77
+ diagnostics: [
78
+ DiagnosticSpec ( message: " expected ':' after '? ...' in ternary expression " , fixIts: [ " insert ':' " ] )
79
+ ] ,
80
+ fixedSource: " foo ? 1 : 2 "
81
+ )
82
+ }
83
+
84
+ func testInvalidIfExpr6( ) {
85
+ assertParse (
86
+ """
87
+ foo ? 1 1️⃣
88
+ """ ,
89
+ diagnostics: [
90
+ DiagnosticSpec ( message: " expected ':' and expression after '? ...' in ternary expression " , fixIts: [ " insert ':' and expression " ] )
91
+ ] ,
92
+ fixedSource: " foo ? 1 : <#expression#> "
93
+ )
94
+ }
95
+
96
+ func testInvalidIfExpr7( ) {
97
+ assertParse (
98
+ """
99
+ condition ? 1 1️⃣
100
+ someOtherVariable
101
+ """ ,
102
+ diagnostics: [
103
+ DiagnosticSpec ( message: " expected ':' and expression after '? ...' in ternary expression " , fixIts: [ " insert ':' and expression " ] )
104
+ ] ,
105
+ fixedSource: """
106
+ condition ? 1 : <#expression#>
107
+ someOtherVariable
108
+ """
109
+ )
110
+ }
72
111
}
You can’t perform that action at this time.
0 commit comments