authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-10 16:08:10-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-10 17:52:18-07:00
loga30d283981ae31ed0212ef153f086e07daeffe65
tree88be9a44382b0a79f42a74a3bb43781e6365fea7
parentb642fa24a67f88082b768d39e443b03c7446be76

AstGen: lower anon struct inits differently

This is a companion commit to f2a5d0bf94897554e25e889dc1c6c4c7fc6c1217. What that one did for tuples, this one does for anonymous structs.

2 files changed, 13 insertions(+), 3 deletions(-)

src/AstGen.zig+13-1
......@@ -1352,6 +1352,7 @@ fn arrayInitExpr(
13521352 if (types.array == .none) {
13531353 // We treat this case differently so that we don't get a crash when
13541354 // analyzing array_base_ptr against an alloc_inferred_mut.
1355 // See corresponding logic in structInitExpr.
13551356 const result = try arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon);
13561357 return rvalue(gz, rl, result, node);
13571358 } else {
......@@ -1591,7 +1592,18 @@ fn structInitExpr(
15911592 const result = try structInitExprRlTy(gz, scope, node, struct_init, inner_ty_inst, .struct_init);
15921593 return rvalue(gz, rl, result, node);
15931594 },
1594 .ptr, .inferred_ptr => |ptr_inst| return structInitExprRlPtr(gz, scope, rl, node, struct_init, ptr_inst),
1595 .ptr => |ptr_inst| return structInitExprRlPtr(gz, scope, rl, node, struct_init, ptr_inst),
1596 .inferred_ptr => |ptr_inst| {
1597 if (struct_init.ast.type_expr == 0) {
1598 // We treat this case differently so that we don't get a crash when
1599 // analyzing field_base_ptr against an alloc_inferred_mut.
1600 // See corresponding logic in arrayInitExpr.
1601 const result = try structInitExprRlNone(gz, scope, node, struct_init, .struct_init_anon);
1602 return rvalue(gz, rl, result, node);
1603 } else {
1604 return structInitExprRlPtr(gz, scope, rl, node, struct_init, ptr_inst);
1605 }
1606 },
15951607 .block_ptr => |block_gz| return structInitExprRlPtr(gz, scope, rl, node, struct_init, block_gz.rl_ptr),
15961608 }
15971609}
test/behavior/tuple.zig-2
......@@ -110,8 +110,6 @@ test "pass tuple to comptime var parameter" {
110110}
111111
112112test "tuple initializer for var" {
113 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
114
115113 const S = struct {
116114 fn doTheTest() void {
117115 const Bytes = struct {