mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
zig fmt: aggregate type init with only 1 field
This commit is contained in:
parent
1d06915f27
commit
eed49a2104
@ -3872,6 +3872,15 @@ pub const Parser = struct {
|
||||
try stack.append(RenderState { .Expression = suffix_op.lhs });
|
||||
continue;
|
||||
}
|
||||
if (field_inits.len == 1) {
|
||||
const field_init = field_inits.at(0);
|
||||
|
||||
try stack.append(RenderState { .Text = "}" });
|
||||
try stack.append(RenderState { .FieldInitializer = field_init });
|
||||
try stack.append(RenderState { .Text = " {" });
|
||||
try stack.append(RenderState { .Expression = suffix_op.lhs });
|
||||
continue;
|
||||
}
|
||||
try stack.append(RenderState { .Text = "}"});
|
||||
try stack.append(RenderState.PrintIndent);
|
||||
try stack.append(RenderState { .Indent = indent });
|
||||
|
||||
@ -1,3 +1,12 @@
|
||||
test "zig fmt: aggregate type init with only 1 field" {
|
||||
try testCanonical(
|
||||
\\comptime {
|
||||
\\ assert(bar(Payload {.A = 1234}) == -10);
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: union(enum(u32)) with assigned enum values" {
|
||||
try testCanonical(
|
||||
\\const MultipleChoice = union(enum(u32)) {
|
||||
@ -709,9 +718,7 @@ test "zig fmt: switch" {
|
||||
\\ Float: f64,
|
||||
\\ };
|
||||
\\
|
||||
\\ const u = Union {
|
||||
\\ .Int = 0,
|
||||
\\ };
|
||||
\\ const u = Union {.Int = 0};
|
||||
\\ switch (u) {
|
||||
\\ Union.Int => |int| {},
|
||||
\\ Union.Float => |*float| unreachable,
|
||||
@ -1029,6 +1036,7 @@ test "zig fmt: struct literals with fields on each line" {
|
||||
try testCanonical(
|
||||
\\var self = BufSet {
|
||||
\\ .hash_map = BufSetHashMap.init(a),
|
||||
\\ .hash_map2 = xyz,
|
||||
\\};
|
||||
\\
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user