zig fmt: fix infix operator before multiline string literal

This commit is contained in:
Andrew Kelley 2019-02-18 18:11:12 -05:00
parent 74bdc1d1f8
commit b0ceea1831
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 12 additions and 2 deletions

View File

@ -1,3 +1,12 @@
test "zig fmt: infix operator and then multiline string literal" {
try testCanonical(
\\const x = "" ++
\\ \\ hi
\\;
\\
);
}
test "zig fmt: C pointers" { test "zig fmt: C pointers" {
try testCanonical( try testCanonical(
\\const Ptr = [*c]i32; \\const Ptr = [*c]i32;

View File

@ -340,7 +340,6 @@ fn renderExpression(
ast.Node.Id.InfixOp => { ast.Node.Id.InfixOp => {
const infix_op_node = @fieldParentPtr(ast.Node.InfixOp, "base", base); const infix_op_node = @fieldParentPtr(ast.Node.InfixOp, "base", base);
const op_token = tree.tokens.at(infix_op_node.op_token);
const op_space = switch (infix_op_node.op) { const op_space = switch (infix_op_node.op) {
ast.Node.InfixOp.Op.Period, ast.Node.InfixOp.Op.ErrorUnion, ast.Node.InfixOp.Op.Range => Space.None, ast.Node.InfixOp.Op.Period, ast.Node.InfixOp.Op.ErrorUnion, ast.Node.InfixOp.Op.Range => Space.None,
else => Space.Space, else => Space.Space,
@ -353,7 +352,9 @@ fn renderExpression(
}; };
try renderToken(tree, stream, infix_op_node.op_token, indent, start_col, after_op_space); try renderToken(tree, stream, infix_op_node.op_token, indent, start_col, after_op_space);
if (after_op_space == Space.Newline) { if (after_op_space == Space.Newline and
tree.tokens.at(tree.nextToken(infix_op_node.op_token)).id != Token.Id.MultilineStringLiteralLine)
{
try stream.writeByteNTimes(' ', indent + indent_delta); try stream.writeByteNTimes(' ', indent + indent_delta);
start_col.* = indent + indent_delta; start_col.* = indent + indent_delta;
} }