parent
0adc144f88
commit
7bc9531698
|
@ -16313,6 +16313,9 @@ static void set_optional_payload(ZigValue *opt_val, ZigValue *payload) {
|
||||||
assert(opt_val->type->id == ZigTypeIdOptional);
|
assert(opt_val->type->id == ZigTypeIdOptional);
|
||||||
if (payload == nullptr) {
|
if (payload == nullptr) {
|
||||||
set_optional_value_to_null(opt_val);
|
set_optional_value_to_null(opt_val);
|
||||||
|
} else if (get_src_ptr_type(opt_val->type)) {
|
||||||
|
assert(get_src_ptr_type(payload->type));
|
||||||
|
opt_val->data.x_ptr = payload->data.x_ptr;
|
||||||
} else if (is_opt_err_set(opt_val->type)) {
|
} else if (is_opt_err_set(opt_val->type)) {
|
||||||
assert(payload->type->id == ZigTypeIdErrorSet);
|
assert(payload->type->id == ZigTypeIdErrorSet);
|
||||||
opt_val->data.x_err_set = payload->data.x_err_set;
|
opt_val->data.x_err_set = payload->data.x_err_set;
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const expect = std.testing.expect;
|
const builtin = std.builtin;
|
||||||
const mem = std.mem;
|
const mem = std.mem;
|
||||||
const builtin = @import("builtin");
|
|
||||||
const TypeInfo = builtin.TypeInfo;
|
const TypeInfo = builtin.TypeInfo;
|
||||||
const TypeId = builtin.TypeId;
|
const TypeId = builtin.TypeId;
|
||||||
|
|
||||||
|
const expect = std.testing.expect;
|
||||||
|
const expectEqualStrings = std.testing.expectEqualStrings;
|
||||||
|
|
||||||
test "type info: tag type, void info" {
|
test "type info: tag type, void info" {
|
||||||
testBasic();
|
testBasic();
|
||||||
comptime testBasic();
|
comptime testBasic();
|
||||||
|
@ -232,10 +235,14 @@ test "type info: struct info" {
|
||||||
|
|
||||||
fn testStruct() void {
|
fn testStruct() void {
|
||||||
const unpacked_struct_info = @typeInfo(TestUnpackedStruct);
|
const unpacked_struct_info = @typeInfo(TestUnpackedStruct);
|
||||||
|
expect(unpacked_struct_info.Struct.is_tuple == false);
|
||||||
expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32));
|
expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32));
|
||||||
|
expect(unpacked_struct_info.Struct.fields[0].default_value.? == 4);
|
||||||
|
expectEqualStrings("foobar", unpacked_struct_info.Struct.fields[1].default_value.?);
|
||||||
|
|
||||||
const struct_info = @typeInfo(TestStruct);
|
const struct_info = @typeInfo(TestStruct);
|
||||||
expect(struct_info == .Struct);
|
expect(struct_info == .Struct);
|
||||||
|
expect(struct_info.Struct.is_tuple == false);
|
||||||
expect(struct_info.Struct.layout == .Packed);
|
expect(struct_info.Struct.layout == .Packed);
|
||||||
expect(struct_info.Struct.fields.len == 4);
|
expect(struct_info.Struct.fields.len == 4);
|
||||||
expect(struct_info.Struct.fields[0].alignment == 2 * @alignOf(usize));
|
expect(struct_info.Struct.fields[0].alignment == 2 * @alignOf(usize));
|
||||||
|
@ -253,6 +260,7 @@ fn testStruct() void {
|
||||||
|
|
||||||
const TestUnpackedStruct = struct {
|
const TestUnpackedStruct = struct {
|
||||||
fieldA: u32 = 4,
|
fieldA: u32 = 4,
|
||||||
|
fieldB: *const [6:0]u8 = "foobar",
|
||||||
};
|
};
|
||||||
|
|
||||||
const TestStruct = packed struct {
|
const TestStruct = packed struct {
|
||||||
|
@ -371,7 +379,7 @@ test "type info: extern fns with and without lib names" {
|
||||||
if (std.mem.eql(u8, decl.name, "bar1")) {
|
if (std.mem.eql(u8, decl.name, "bar1")) {
|
||||||
expect(decl.data.Fn.lib_name == null);
|
expect(decl.data.Fn.lib_name == null);
|
||||||
} else {
|
} else {
|
||||||
std.testing.expectEqual(@as([]const u8, "cool"), decl.data.Fn.lib_name.?);
|
expectEqualStrings("cool", decl.data.Fn.lib_name.?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue