authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-10-25 12:25:34+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-10-28 21:56:28+02:00
log7bc95316982da0da6fd5d935645972fe5464e46e
tree8ba243f467260d4cb3847b59facd0b252e32d6fe
parent0adc144f88b567054e63df808aac0227445e88bb

stage1: Correctly generated optional constant values

Closes #6799

2 files changed, 14 insertions(+), 3 deletions(-)

src/stage1/ir.cpp+3
......@@ -16313,6 +16313,9 @@ static void set_optional_payload(ZigValue *opt_val, ZigValue *payload) {
1631316313 assert(opt_val->type->id == ZigTypeIdOptional);
1631416314 if (payload == nullptr) {
1631516315 set_optional_value_to_null(opt_val);
16316 } else if (get_src_ptr_type(opt_val->type)) {
16317 assert(get_src_ptr_type(payload->type));
16318 opt_val->data.x_ptr = payload->data.x_ptr;
1631616319 } else if (is_opt_err_set(opt_val->type)) {
1631716320 assert(payload->type->id == ZigTypeIdErrorSet);
1631816321 opt_val->data.x_err_set = payload->data.x_err_set;
test/stage1/behavior/type_info.zig+11-3
......@@ -1,10 +1,13 @@
11const std = @import("std");
2const expect = std.testing.expect;
2const builtin = std.builtin;
33const mem = std.mem;
4const builtin = @import("builtin");
4
55const TypeInfo = builtin.TypeInfo;
66const TypeId = builtin.TypeId;
77
8const expect = std.testing.expect;
9const expectEqualStrings = std.testing.expectEqualStrings;
10
811test "type info: tag type, void info" {
912 testBasic();
1013 comptime testBasic();
......@@ -232,10 +235,14 @@ test "type info: struct info" {
232235
233236fn testStruct() void {
234237 const unpacked_struct_info = @typeInfo(TestUnpackedStruct);
238 expect(unpacked_struct_info.Struct.is_tuple == false);
235239 expect(unpacked_struct_info.Struct.fields[0].alignment == @alignOf(u32));
240 expect(unpacked_struct_info.Struct.fields[0].default_value.? == 4);
241 expectEqualStrings("foobar", unpacked_struct_info.Struct.fields[1].default_value.?);
236242
237243 const struct_info = @typeInfo(TestStruct);
238244 expect(struct_info == .Struct);
245 expect(struct_info.Struct.is_tuple == false);
239246 expect(struct_info.Struct.layout == .Packed);
240247 expect(struct_info.Struct.fields.len == 4);
241248 expect(struct_info.Struct.fields[0].alignment == 2 * @alignOf(usize));
......@@ -253,6 +260,7 @@ fn testStruct() void {
253260
254261const TestUnpackedStruct = struct {
255262 fieldA: u32 = 4,
263 fieldB: *const [6:0]u8 = "foobar",
256264};
257265
258266const TestStruct = packed struct {
......@@ -371,7 +379,7 @@ test "type info: extern fns with and without lib names" {
371379 if (std.mem.eql(u8, decl.name, "bar1")) {
372380 expect(decl.data.Fn.lib_name == null);
373381 } else {
374 std.testing.expectEqual(@as([]const u8, "cool"), decl.data.Fn.lib_name.?);
382 expectEqualStrings("cool", decl.data.Fn.lib_name.?);
375383 }
376384 }
377385 }