File tree Expand file tree Collapse file tree
Tests/SwiftParserTest/translated Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -316,10 +316,7 @@ extension Parser {
316316 )
317317
318318 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 {
323320 rhs = RawExprSyntax ( RawMissingExprSyntax ( arena: self . arena) )
324321 } else {
325322 rhs = nil
Original file line number Diff line number Diff line change @@ -69,4 +69,43 @@ final class InvalidIfExprTests: XCTestCase {
6969 )
7070 }
7171
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+ }
72111}
You can’t perform that action at this time.
0 commit comments