authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-28 14:07:01+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-28 15:41:21+03:00
log15cc4514e0566430ed1d95e85aaa462642b70364
treeb4522e711412cc2a53924ae2303cd29631ffc28c
parente2dc77ab62edf5446af830356eceef8eefb67cfa

Sema: add missing calls to resolveStructLayout

Closes #12645

2 files changed, 19 insertions(+), 1 deletions(-)

src/Sema.zig+4-1
......@@ -3779,6 +3779,7 @@ fn validateStructInit(
37793779 if ((is_comptime or block.is_comptime) and
37803780 (try sema.resolveDefinedValue(block, init_src, struct_ptr)) != null)
37813781 {
3782 try sema.resolveStructLayout(block, init_src, struct_ty);
37823783 // In this case the only thing we need to do is evaluate the implicit
37833784 // store instructions for default field values, and report any missing fields.
37843785 // Avoid the cost of the extra machinery for detecting a comptime struct init value.
......@@ -3973,6 +3974,7 @@ fn validateStructInit(
39733974 try sema.storePtr2(block, init_src, struct_ptr, init_src, struct_init, init_src, .store);
39743975 return;
39753976 }
3977 try sema.resolveStructLayout(block, init_src, struct_ty);
39763978
39773979 // Our task is to insert `store` instructions for all the default field values.
39783980 for (found_fields) |field_ptr, i| {
......@@ -15843,6 +15845,7 @@ fn finishStructInit(
1584315845 }
1584415846
1584515847 if (is_ref) {
15848 try sema.resolveStructLayout(block, dest_src, struct_ty);
1584615849 const target = sema.mod.getTarget();
1584715850 const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{
1584815851 .pointee_type = struct_ty,
......@@ -28850,7 +28853,7 @@ pub fn typeHasOnePossibleValue(
2885028853 for (tuple.values) |val, i| {
2885128854 const is_comptime = val.tag() != .unreachable_value;
2885228855 if (is_comptime) continue;
28853 if ((try sema.typeHasOnePossibleValue(block, src, tuple.types[i])) != null) continue;
28856 if ((try sema.typeHasOnePossibleValue(block, src, tuple.types[i])) != null) continue;
2885428857 return null;
2885528858 }
2885628859 return Value.initTag(.empty_struct_value);
test/behavior/packed-struct.zig+15
......@@ -564,3 +564,18 @@ test "nested packed struct field access test" {
564564 try std.testing.expect(arg.g.h == 6);
565565 try std.testing.expect(arg.g.i == 8);
566566}
567
568test "runtime init of unnamed packed struct type" {
569 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
570 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
571 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
572 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
573
574 var z: u8 = 123;
575 try (packed struct {
576 x: u8,
577 pub fn m(s: @This()) !void {
578 try expect(s.x == 123);
579 }
580 }{ .x = z }).m();
581}