Sema: implement zirStructInit for runtime-known union values

This commit is contained in:
Veikka Tuominen 2022-03-25 13:27:03 +02:00
parent 5ff518fbb9
commit 17d214a249
2 changed files with 20 additions and 1 deletions

View File

@ -12264,7 +12264,9 @@ fn zirStructInit(
return alloc;
}
return sema.fail(block, src, "TODO: Sema.zirStructInit for runtime-known union values", .{});
try sema.requireRuntimeBlock(block, src);
try sema.queueFullTypeResolution(resolved_ty);
return block.addUnionInit(resolved_ty, field_index, init_inst);
}
unreachable;
}

View File

@ -1132,3 +1132,20 @@ test "global variable struct contains union initialized to non-most-aligned fiel
T.s.u.a += 1;
try expect(T.s.u.a == 4);
}
test "union with no result loc initiated with a runtime value" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
const U = union {
a: u32,
b: u32,
fn foo(u: @This()) void {
_ = u;
}
};
var a: u32 = 1;
U.foo(U{ .a = a });
}