Skip to content

Commit 77c39f9

Browse files
committed
Insert a space before colon in ternary expression
1 parent 7fbb726 commit 77c39f9

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

Sources/SwiftParserDiagnostics/ParseDiagnosticsGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
14561456
FixIt(
14571457
message: InsertTokenFixIt(missingNodes: [Syntax(node.colonMark), Syntax(nextSibling)]),
14581458
changes: [
1459-
.makePresent(node.colonMark),
1459+
.makePresent(node.colonMark, leadingTrivia: .space),
14601460
.makePresent(nextSibling),
14611461
]
14621462
)

Tests/SwiftParserTest/DeclarationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ final class DeclarationTests: XCTestCase {
256256
DiagnosticSpec(message: "expected ':' and expression after '? ...' in ternary expression", fixIts: ["insert ':' and expression"])
257257
],
258258
fixedSource: """
259-
_ = foo/* */?.description: <#expression#>
259+
_ = foo/* */?.description : <#expression#>
260260
"""
261261
)
262262

Tests/SwiftParserTest/ExpressionTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ final class ExpressionTests: XCTestCase {
836836
DiagnosticSpec(message: "expected ':' and expression after '? ...' in ternary expression", fixIts: ["insert ':' and expression"])
837837
],
838838
fixedSource: """
839-
foo ? 1: <#expression#>
839+
foo ? 1 : <#expression#>
840840
"""
841841
)
842842
}

Tests/SwiftParserTest/translated/InvalidIfExprTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class InvalidIfExprTests: XCTestCase {
2323
diagnostics: [
2424
DiagnosticSpec(message: "expected ':' and expression after '? ...' in ternary expression", fixIts: ["insert ':' and expression"])
2525
],
26-
fixedSource: "(a ? b: <#expression#>)"
26+
fixedSource: "(a ? b : <#expression#>)"
2727
)
2828
}
2929

@@ -35,7 +35,7 @@ final class InvalidIfExprTests: XCTestCase {
3535
diagnostics: [
3636
DiagnosticSpec(message: "expected ':' and expression after '? ...' in ternary expression", fixIts: ["insert ':' and expression"])
3737
],
38-
fixedSource: "(a ? b : c ? d: <#expression#>)"
38+
fixedSource: "(a ? b : c ? d : <#expression#>)"
3939
)
4040
}
4141

@@ -52,7 +52,7 @@ final class InvalidIfExprTests: XCTestCase {
5252
fixIts: ["insert ')'"]
5353
),
5454
],
55-
fixedSource: "(a ? b ? c : d: <#expression#>)"
55+
fixedSource: "(a ? b ? c : d : <#expression#>)"
5656
)
5757
}
5858

@@ -65,7 +65,7 @@ final class InvalidIfExprTests: XCTestCase {
6565
DiagnosticSpec(message: "expected ':' and expression after '? ...' in ternary expression", fixIts: ["insert ':' and expression"]),
6666
DiagnosticSpec(message: "expected ':' and expression after '? ...' in ternary expression", fixIts: ["insert ':' and expression"]),
6767
],
68-
fixedSource: "(a ? b ? c: <#expression#>: <#expression#>)"
68+
fixedSource: "(a ? b ? c : <#expression#> : <#expression#>)"
6969
)
7070
}
7171

0 commit comments

Comments
 (0)