authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-09 15:19:51+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-15 00:48:47+03:00
logde24cea2cff33654ee41369517144bb94f6d139d
tree967afd2c0af7bf975fa8b29de278e11708a80df7
parent61aaef0b074dc2567e4c35c9cb55cb042c18d065

Sema: handle empty_struct_value in beginComptimePtrMutation

Closes #12794

3 files changed, 53 insertions(+), 0 deletions(-)

src/Sema.zig+14
......@@ -24770,6 +24770,20 @@ fn beginComptimePtrMutation(
2477024770 else => unreachable,
2477124771 },
2477224772
24773 .empty_struct_value => {
24774 const duped = try sema.arena.create(Value);
24775 duped.* = Value.initTag(.the_only_possible_value);
24776 return beginComptimePtrMutationInner(
24777 sema,
24778 block,
24779 src,
24780 parent.ty.structFieldType(field_index),
24781 duped,
24782 ptr_elem_ty,
24783 parent.decl_ref_mut,
24784 );
24785 },
24786
2477324787 else => unreachable,
2477424788 },
2477524789 .reinterpret => |reinterpret| {
test/behavior.zig+1
......@@ -87,6 +87,7 @@ test {
8787 _ = @import("behavior/bugs/12486.zig");
8888 _ = @import("behavior/bugs/12680.zig");
8989 _ = @import("behavior/bugs/12776.zig");
90 _ = @import("behavior/bugs/12794.zig");
9091 _ = @import("behavior/byteswap.zig");
9192 _ = @import("behavior/byval_arg_var.zig");
9293 _ = @import("behavior/call.zig");
test/behavior/bugs/12794.zig created+38
......@@ -0,0 +1,38 @@
1const std = @import("std");
2
3fn NamespacedComponents(comptime modules: anytype) type {
4 return @Type(.{
5 .Struct = .{
6 .layout = .Auto,
7 .is_tuple = false,
8 .fields = &.{.{
9 .name = "components",
10 .field_type = @TypeOf(modules.components),
11 .default_value = null,
12 .is_comptime = false,
13 .alignment = @alignOf(@TypeOf(modules.components)),
14 }},
15 .decls = &[_]std.builtin.Type.Declaration{},
16 },
17 });
18}
19
20fn namespacedComponents(comptime modules: anytype) NamespacedComponents(modules) {
21 var x: NamespacedComponents(modules) = undefined;
22 x.components = modules.components;
23 return x;
24}
25
26pub fn World(comptime modules: anytype) type {
27 const all_components = namespacedComponents(modules);
28 _ = all_components;
29 return struct {};
30}
31
32test {
33 _ = World(.{
34 .components = .{
35 .location = struct {},
36 },
37 });
38}