Sema: handle empty_struct_value in beginComptimePtrMutation

Closes #12794
This commit is contained in:
Veikka Tuominen 2022-09-09 15:19:51 +03:00
parent 61aaef0b07
commit de24cea2cf
3 changed files with 53 additions and 0 deletions

View File

@ -24770,6 +24770,20 @@ fn beginComptimePtrMutation(
else => unreachable,
},
.empty_struct_value => {
const duped = try sema.arena.create(Value);
duped.* = Value.initTag(.the_only_possible_value);
return beginComptimePtrMutationInner(
sema,
block,
src,
parent.ty.structFieldType(field_index),
duped,
ptr_elem_ty,
parent.decl_ref_mut,
);
},
else => unreachable,
},
.reinterpret => |reinterpret| {

View File

@ -87,6 +87,7 @@ test {
_ = @import("behavior/bugs/12486.zig");
_ = @import("behavior/bugs/12680.zig");
_ = @import("behavior/bugs/12776.zig");
_ = @import("behavior/bugs/12794.zig");
_ = @import("behavior/byteswap.zig");
_ = @import("behavior/byval_arg_var.zig");
_ = @import("behavior/call.zig");

View File

@ -0,0 +1,38 @@
const std = @import("std");
fn NamespacedComponents(comptime modules: anytype) type {
return @Type(.{
.Struct = .{
.layout = .Auto,
.is_tuple = false,
.fields = &.{.{
.name = "components",
.field_type = @TypeOf(modules.components),
.default_value = null,
.is_comptime = false,
.alignment = @alignOf(@TypeOf(modules.components)),
}},
.decls = &[_]std.builtin.Type.Declaration{},
},
});
}
fn namespacedComponents(comptime modules: anytype) NamespacedComponents(modules) {
var x: NamespacedComponents(modules) = undefined;
x.components = modules.components;
return x;
}
pub fn World(comptime modules: anytype) type {
const all_components = namespacedComponents(modules);
_ = all_components;
return struct {};
}
test {
_ = World(.{
.components = .{
.location = struct {},
},
});
}