Skip to content

Commit 7af3b10

Browse files
committed
Format copy expressions.
1 parent 1e9b89b commit 7af3b10

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,13 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
25112511
return .visitChildren
25122512
}
25132513

2514+
override func visit(_ node: CopyExprSyntax) -> SyntaxVisitorContinueKind {
2515+
// The `copy` keyword cannot be separated from the following token or it will be parsed as an
2516+
// identifier.
2517+
after(node.copyKeyword, tokens: .space)
2518+
return .visitChildren
2519+
}
2520+
25142521
override func visit(_ node: DiscardStmtSyntax) -> SyntaxVisitorContinueKind {
25152522
// The `discard` keyword cannot be separated from the following token or it will be parsed as
25162523
// an identifier.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
final class CopyExprTests: PrettyPrintTestCase {
2+
func testCopy() {
3+
assertPrettyPrintEqual(
4+
input: """
5+
let x = copy y
6+
""",
7+
expected: """
8+
let x =
9+
copy y
10+
11+
""",
12+
linelength: 13)
13+
}
14+
}

0 commit comments

Comments
 (0)