| author | |
| committer | |
| log | e23bc1f76af298e7ba0140e442858c1faa98e379 |
| tree | ae6286a19b8cf027221f47d8fe5349e5861e1e43 |
| parent | 4ca1f4ec2e3ae1a08295bc6ed03c235cb7700ab9 |
This crashed the compiler when running translate-c. See the added test.2 files changed, 20 insertions(+), 8 deletions(-)
lib/std/zig/render.zig+8-8| ... | @@ -965,13 +965,13 @@ fn renderExpression( | ... | @@ -965,13 +965,13 @@ fn renderExpression( |
| 965 | }; | 965 | }; |
| 966 | 966 | ||
| 967 | if (field_inits.len == 1) blk: { | 967 | if (field_inits.len == 1) blk: { |
| 968 | const field_init = field_inits[0].cast(ast.Node.FieldInitializer).?; | 968 | if (field_inits[0].cast(ast.Node.FieldInitializer)) |field_init| { |
| 969 | 969 | switch (field_init.expr.tag) { | |
| 970 | switch (field_init.expr.tag) { | 970 | .StructInitializer, |
| 971 | .StructInitializer, | 971 | .StructInitializerDot, |
| 972 | .StructInitializerDot, | 972 | => break :blk, |
| 973 | => break :blk, | 973 | else => {}, |
| 974 | else => {}, | 974 | } |
| 975 | } | 975 | } |
| 976 | 976 | ||
| 977 | // if the expression outputs to multiline, make this struct multiline | 977 | // if the expression outputs to multiline, make this struct multiline |
| ... | @@ -984,7 +984,7 @@ fn renderExpression( | ... | @@ -984,7 +984,7 @@ fn renderExpression( |
| 984 | .node => |node| try renderExpression(allocator, ais, tree, node, Space.None), | 984 | .node => |node| try renderExpression(allocator, ais, tree, node, Space.None), |
| 985 | } | 985 | } |
| 986 | try renderToken(tree, ais, lbrace, Space.Space); | 986 | try renderToken(tree, ais, lbrace, Space.Space); |
| 987 | try renderExpression(allocator, ais, tree, &field_init.base, Space.Space); | 987 | try renderExpression(allocator, ais, tree, field_inits[0], Space.Space); |
| 988 | return renderToken(tree, ais, rtoken, space); | 988 | return renderToken(tree, ais, rtoken, space); |
| 989 | } | 989 | } |
| 990 | 990 |
test/translate_c.zig+12| ... | @@ -102,6 +102,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -102,6 +102,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 102 | \\} Color; | 102 | \\} Color; |
| 103 | \\#define CLITERAL(type) (type) | 103 | \\#define CLITERAL(type) (type) |
| 104 | \\#define LIGHTGRAY CLITERAL(Color){ 200, 200, 200, 255 } // Light Gray | 104 | \\#define LIGHTGRAY CLITERAL(Color){ 200, 200, 200, 255 } // Light Gray |
| 105 | \\typedef struct boom_t | ||
| 106 | \\{ | ||
| 107 | \\ int i1; | ||
| 108 | \\} boom_t; | ||
| 109 | \\#define FOO ((boom_t){1}) | ||
| 105 | , &[_][]const u8{ // TODO properly translate this | 110 | , &[_][]const u8{ // TODO properly translate this |
| 106 | \\pub const struct_Color = extern struct { | 111 | \\pub const struct_Color = extern struct { |
| 107 | \\ r: u8, | 112 | \\ r: u8, |
| ... | @@ -116,6 +121,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -116,6 +121,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 116 | \\} | 121 | \\} |
| 117 | , | 122 | , |
| 118 | \\pub const LIGHTGRAY = @import("std").mem.zeroInit(CLITERAL(Color), .{ 200, 200, 200, 255 }); | 123 | \\pub const LIGHTGRAY = @import("std").mem.zeroInit(CLITERAL(Color), .{ 200, 200, 200, 255 }); |
| 124 | , | ||
| 125 | \\pub const struct_boom_t = extern struct { | ||
| 126 | \\ i1: c_int, | ||
| 127 | \\}; | ||
| 128 | \\pub const boom_t = struct_boom_t; | ||
| 129 | , | ||
| 130 | \\pub const FOO = @import("std").mem.zeroInit(boom_t, .{ 1 }); | ||
| 119 | }); | 131 | }); |
| 120 | 132 | ||
| 121 | cases.add("complex switch", | 133 | cases.add("complex switch", |