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(...@@ -1352,6 +1352,7 @@ fn arrayInitExpr(
1352 if (types.array == .none) {1352 if (types.array == .none) {
1353 // We treat this case differently so that we don't get a crash when1353 // We treat this case differently so that we don't get a crash when
1354 // analyzing array_base_ptr against an alloc_inferred_mut.1354 // analyzing array_base_ptr against an alloc_inferred_mut.
1355 // See corresponding logic in structInitExpr.
1355 const result = try arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon);1356 const result = try arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon);
1356 return rvalue(gz, rl, result, node);1357 return rvalue(gz, rl, result, node);
1357 } else {1358 } else {
...@@ -1591,7 +1592,18 @@ fn structInitExpr(...@@ -1591,7 +1592,18 @@ fn structInitExpr(
1591 const result = try structInitExprRlTy(gz, scope, node, struct_init, inner_ty_inst, .struct_init);1592 const result = try structInitExprRlTy(gz, scope, node, struct_init, inner_ty_inst, .struct_init);
1592 return rvalue(gz, rl, result, node);1593 return rvalue(gz, rl, result, node);
1593 },1594 },
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 },
1595 .block_ptr => |block_gz| return structInitExprRlPtr(gz, scope, rl, node, struct_init, block_gz.rl_ptr),1607 .block_ptr => |block_gz| return structInitExprRlPtr(gz, scope, rl, node, struct_init, block_gz.rl_ptr),
1596 }1608 }
1597}1609}
test/behavior/tuple.zig-2
...@@ -110,8 +110,6 @@ test "pass tuple to comptime var parameter" {...@@ -110,8 +110,6 @@ test "pass tuple to comptime var parameter" {
110}110}
111111
112test "tuple initializer for var" {112test "tuple initializer for var" {
113 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
114
115 const S = struct {113 const S = struct {
116 fn doTheTest() void {114 fn doTheTest() void {
117 const Bytes = struct {115 const Bytes = struct {