| author | |
| committer | |
| log | bac27731e30cbea76997fa3547791b3462ac8697 |
| tree | 1e14fcb22dc0957dda325fbc058989609c48b5a0 |
| parent | df03fcf5f07e0d5d16e5b837658265f6c468cbe4 |
3 files changed, 12 insertions(+), 2 deletions(-)
lib/std/builtin.zig+1| ... | ... | @@ -205,6 +205,7 @@ pub const TypeInfo = union(enum) { |
| 205 | 205 | name: []const u8, |
| 206 | 206 | offset: ?comptime_int, |
| 207 | 207 | field_type: type, |
| 208 | default_value: var, | |
| 208 | 209 | }; |
| 209 | 210 | |
| 210 | 211 | /// This data structure is used by the Zig language code generation and |
src/ir.cpp+7-1| ... | ... | @@ -23338,7 +23338,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 23338 | 23338 | struct_field_val->special = ConstValSpecialStatic; |
| 23339 | 23339 | struct_field_val->type = type_info_struct_field_type; |
| 23340 | 23340 | |
| 23341 | ZigValue **inner_fields = alloc_const_vals_ptrs(3); | |
| 23341 | ZigValue **inner_fields = alloc_const_vals_ptrs(4); | |
| 23342 | 23342 | inner_fields[1]->special = ConstValSpecialStatic; |
| 23343 | 23343 | inner_fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int); |
| 23344 | 23344 | |
| ... | ... | @@ -23361,6 +23361,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 23361 | 23361 | inner_fields[2]->type = ira->codegen->builtin_types.entry_type; |
| 23362 | 23362 | inner_fields[2]->data.x_type = struct_field->type_entry; |
| 23363 | 23363 | |
| 23364 | // default_value: var | |
| 23365 | inner_fields[3]->special = ConstValSpecialStatic; | |
| 23366 | inner_fields[3]->type = get_optional_type(ira->codegen, struct_field->type_entry); | |
| 23367 | memoize_field_init_val(ira->codegen, type_entry, struct_field); | |
| 23368 | set_optional_payload(inner_fields[3], struct_field->init_val); | |
| 23369 | ||
| 23364 | 23370 | ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee; |
| 23365 | 23371 | init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true); |
| 23366 | 23372 |
test/stage1/behavior/type_info.zig+4-1| ... | ... | @@ -237,9 +237,11 @@ fn testStruct() void { |
| 237 | 237 | const struct_info = @typeInfo(TestStruct); |
| 238 | 238 | expect(@as(TypeId, struct_info) == TypeId.Struct); |
| 239 | 239 | expect(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed); |
| 240 | expect(struct_info.Struct.fields.len == 3); | |
| 240 | expect(struct_info.Struct.fields.len == 4); | |
| 241 | 241 | expect(struct_info.Struct.fields[1].offset == null); |
| 242 | 242 | expect(struct_info.Struct.fields[2].field_type == *TestStruct); |
| 243 | expect(struct_info.Struct.fields[2].default_value == null); | |
| 244 | expect(struct_info.Struct.fields[3].default_value.? == 4); | |
| 243 | 245 | expect(struct_info.Struct.decls.len == 2); |
| 244 | 246 | expect(struct_info.Struct.decls[0].is_pub); |
| 245 | 247 | expect(!struct_info.Struct.decls[0].data.Fn.is_extern); |
| ... | ... | @@ -254,6 +256,7 @@ const TestStruct = packed struct { |
| 254 | 256 | fieldA: usize, |
| 255 | 257 | fieldB: void, |
| 256 | 258 | fieldC: *Self, |
| 259 | fieldD: u32 = 4, | |
| 257 | 260 | |
| 258 | 261 | pub fn foo(self: *const Self) void {} |
| 259 | 262 | }; |