commit a30d283981ae31ed0212ef153f086e07daeffe65 (tree)
parent b642fa24a67f88082b768d39e443b03c7446be76
Author: Andrew Kelley <andrew@ziglang.org>
Date: Thu, 10 Mar 2022 16:08:10 -0700
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.
Diffstat:
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/AstGen.zig b/src/AstGen.zig
@@ -1352,6 +1352,7 @@ fn arrayInitExpr(
if (types.array == .none) {
// We treat this case differently so that we don't get a crash when
// analyzing array_base_ptr against an alloc_inferred_mut.
+ // See corresponding logic in structInitExpr.
const result = try arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon);
return rvalue(gz, rl, result, node);
} else {
@@ -1591,7 +1592,18 @@ fn structInitExpr(
const result = try structInitExprRlTy(gz, scope, node, struct_init, inner_ty_inst, .struct_init);
return rvalue(gz, rl, result, node);
},
- .ptr, .inferred_ptr => |ptr_inst| return structInitExprRlPtr(gz, scope, rl, node, struct_init, ptr_inst),
+ .ptr => |ptr_inst| return structInitExprRlPtr(gz, scope, rl, node, struct_init, ptr_inst),
+ .inferred_ptr => |ptr_inst| {
+ if (struct_init.ast.type_expr == 0) {
+ // We treat this case differently so that we don't get a crash when
+ // analyzing field_base_ptr against an alloc_inferred_mut.
+ // See corresponding logic in arrayInitExpr.
+ const result = try structInitExprRlNone(gz, scope, node, struct_init, .struct_init_anon);
+ return rvalue(gz, rl, result, node);
+ } else {
+ return structInitExprRlPtr(gz, scope, rl, node, struct_init, ptr_inst);
+ }
+ },
.block_ptr => |block_gz| return structInitExprRlPtr(gz, scope, rl, node, struct_init, block_gz.rl_ptr),
}
}
diff --git a/test/behavior/tuple.zig b/test/behavior/tuple.zig
@@ -110,8 +110,6 @@ test "pass tuple to comptime var parameter" {
}
test "tuple initializer for var" {
- if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
-
const S = struct {
fn doTheTest() void {
const Bytes = struct {