mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
Sema: add missing set_union_tag
This commit is contained in:
parent
6b36774adc
commit
0a9d6956e7
@ -114,7 +114,6 @@ test "StreamSource (mutable buffer)" {
|
||||
}
|
||||
|
||||
test "StreamSource (const buffer)" {
|
||||
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest;
|
||||
const buffer: [64]u8 = "Hello, World!".* ++ ([1]u8{0xAA} ** 51);
|
||||
var source = StreamSource{ .const_buffer = std.io.fixedBufferStream(&buffer) };
|
||||
|
||||
|
||||
@ -1355,7 +1355,6 @@ pub const Value = union(enum) {
|
||||
};
|
||||
|
||||
test "Value.jsonStringify" {
|
||||
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
|
||||
{
|
||||
var buffer: [10]u8 = undefined;
|
||||
var fbs = std.io.fixedBufferStream(&buffer);
|
||||
|
||||
@ -2154,7 +2154,6 @@ test "timeout (after a number of completions)" {
|
||||
}
|
||||
|
||||
test "timeout_remove" {
|
||||
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
|
||||
if (builtin.os.tag != .linux) return error.SkipZigTest;
|
||||
|
||||
var ring = IO_Uring.init(2, 0) catch |err| switch (err) {
|
||||
@ -2951,7 +2950,6 @@ test "provide_buffers: read" {
|
||||
}
|
||||
|
||||
test "remove_buffers" {
|
||||
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
|
||||
if (builtin.os.tag != .linux) return error.SkipZigTest;
|
||||
|
||||
var ring = IO_Uring.init(1, 0) catch |err| switch (err) {
|
||||
|
||||
@ -13757,10 +13757,10 @@ fn zirStructInit(
|
||||
const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
|
||||
const field_name = sema.code.nullTerminatedString(field_type_extra.name_start);
|
||||
const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);
|
||||
const tag_val = try Value.Tag.enum_field_index.create(sema.arena, field_index);
|
||||
|
||||
const init_inst = try sema.resolveInst(item.data.init);
|
||||
if (try sema.resolveMaybeUndefVal(block, field_src, init_inst)) |val| {
|
||||
const tag_val = try Value.Tag.enum_field_index.create(sema.arena, field_index);
|
||||
return sema.addConstantMaybeRef(
|
||||
block,
|
||||
src,
|
||||
@ -13779,6 +13779,8 @@ fn zirStructInit(
|
||||
const alloc = try block.addTy(.alloc, alloc_ty);
|
||||
const field_ptr = try sema.unionFieldPtr(block, field_src, alloc, field_name, field_src, resolved_ty);
|
||||
try sema.storePtr(block, src, field_ptr, init_inst);
|
||||
const new_tag = try sema.addConstant(resolved_ty.unionTagTypeHypothetical(), tag_val);
|
||||
_ = try block.addBinOp(.set_union_tag, alloc, new_tag);
|
||||
return alloc;
|
||||
}
|
||||
|
||||
|
||||
@ -1183,3 +1183,21 @@ test "comptime equality of extern unions with same tag" {
|
||||
const b = S.U{ .a = 1234 };
|
||||
try expect(S.foo(a) == S.foo(b));
|
||||
}
|
||||
|
||||
test "union tag is set when initiated as a temporary value at runtime" {
|
||||
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
|
||||
|
||||
const U = union(enum) {
|
||||
a,
|
||||
b: u32,
|
||||
c,
|
||||
|
||||
fn doTheTest(u: @This()) !void {
|
||||
try expect(u == .b);
|
||||
}
|
||||
};
|
||||
var b: u32 = 1;
|
||||
try (U{ .b = b }).doTheTest();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user