| author | |
| committer | |
| log | 2148943fff5af1e31f75b1e6651f0b7614e7e36a |
| tree | 28b57538d63b452532f8d37ddf87be22bd009245 |
| parent | fed5c12d9a2ab14c5bb66251ba6ee3e356bce8d3 |
| parent | 19964f5dc80792eb50cb3a45bdabe887a92d92cc |
| signature |
zig fmt: fix nested if3 files changed, 32 insertions(+), 8 deletions(-)
std/special/compiler_rt/comparetf2.zig+7-6| ... | ... | @@ -38,12 +38,14 @@ pub extern fn __letf2(a: f128, b: f128) c_int { |
| 38 | 38 | |
| 39 | 39 | // If at least one of a and b is positive, we get the same result comparing |
| 40 | 40 | // a and b as signed integers as we would with a floating-point compare. |
| 41 | return if ((aInt & bInt) >= 0) if (aInt < bInt) | |
| 42 | LE_LESS | |
| 43 | else if (aInt == bInt) | |
| 44 | LE_EQUAL | |
| 41 | return if ((aInt & bInt) >= 0) | |
| 42 | if (aInt < bInt) | |
| 43 | LE_LESS | |
| 44 | else if (aInt == bInt) | |
| 45 | LE_EQUAL | |
| 46 | else | |
| 47 | LE_GREATER | |
| 45 | 48 | else |
| 46 | LE_GREATER else | |
| 47 | 49 | // Otherwise, both are negative, so we need to flip the sense of the |
| 48 | 50 | // comparison to get the correct result. (This assumes a twos- or ones- |
| 49 | 51 | // complement integer representation; if integers are represented in a |
| ... | ... | @@ -73,7 +75,6 @@ pub extern fn __getf2(a: f128, b: f128) c_int { |
| 73 | 75 | |
| 74 | 76 | if (aAbs > infRep or bAbs > infRep) return GE_UNORDERED; |
| 75 | 77 | if ((aAbs | bAbs) == 0) return GE_EQUAL; |
| 76 | // zig fmt issue here, see https://github.com/ziglang/zig/issues/2661 | |
| 77 | 78 | return if ((aInt & bInt) >= 0) |
| 78 | 79 | if (aInt < bInt) |
| 79 | 80 | GE_LESS |
std/zig/parser_test.zig+21| ... | ... | @@ -482,6 +482,27 @@ test "zig fmt: if-else with comment before else" { |
| 482 | 482 | ); |
| 483 | 483 | } |
| 484 | 484 | |
| 485 | test "zig fmt: if nested" { | |
| 486 | try testCanonical( | |
| 487 | \\pub fn foo() void { | |
| 488 | \\ return if ((aInt & bInt) >= 0) | |
| 489 | \\ if (aInt < bInt) | |
| 490 | \\ GE_LESS | |
| 491 | \\ else if (aInt == bInt) | |
| 492 | \\ GE_EQUAL | |
| 493 | \\ else | |
| 494 | \\ GE_GREATER | |
| 495 | \\ else if (aInt > bInt) | |
| 496 | \\ GE_LESS | |
| 497 | \\ else if (aInt == bInt) | |
| 498 | \\ GE_EQUAL | |
| 499 | \\ else | |
| 500 | \\ GE_GREATER; | |
| 501 | \\} | |
| 502 | \\ | |
| 503 | ); | |
| 504 | } | |
| 505 | ||
| 485 | 506 | test "zig fmt: respect line breaks in if-else" { |
| 486 | 507 | try testCanonical( |
| 487 | 508 | \\comptime { |
std/zig/render.zig+4-2| ... | ... | @@ -276,7 +276,6 @@ fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, i |
| 276 | 276 | } else { |
| 277 | 277 | try renderExpression(allocator, stream, tree, indent, start_col, field.type_expr.?, Space.Comma); // type, |
| 278 | 278 | } |
| 279 | ||
| 280 | 279 | } else if (field.type_expr == null and field.value_expr != null) { |
| 281 | 280 | try renderToken(tree, stream, field.name_token, indent, start_col, Space.Space); // name |
| 282 | 281 | try renderToken(tree, stream, tree.nextToken(field.name_token), indent, start_col, Space.Space); // = |
| ... | ... | @@ -1521,9 +1520,12 @@ fn renderExpression( |
| 1521 | 1520 | |
| 1522 | 1521 | try renderExpression(allocator, stream, tree, indent, start_col, if_node.condition, Space.None); // condition |
| 1523 | 1522 | |
| 1523 | const body_is_if_block = if_node.body.id == ast.Node.Id.If; | |
| 1524 | 1524 | const body_is_block = nodeIsBlock(if_node.body); |
| 1525 | 1525 | |
| 1526 | if (body_is_block) { | |
| 1526 | if (body_is_if_block) { | |
| 1527 | try renderExtraNewline(tree, stream, start_col, if_node.body); | |
| 1528 | } else if (body_is_block) { | |
| 1527 | 1529 | const after_rparen_space = if (if_node.payload == null) Space.BlockStart else Space.Space; |
| 1528 | 1530 | try renderToken(tree, stream, rparen, indent, start_col, after_rparen_space); // ) |
| 1529 | 1531 |