Commit 7d0b6956c0
Changed files (3)
src
test
behavior
bugs
src/Sema.zig
@@ -2672,11 +2672,16 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
// ZIR handles it later, so we can just use the ty ref here.
air_datas[ptr_inst].ty_pl.ty = air_datas[bitcast_inst].ty_op.ty;
+ // Unless the block is comptime, `alloc_inferred` always produces
+ // a runtime constant. The final inferred type needs to be
+ // fully resolved so it can be lowered in codegen.
+ try sema.resolveTypeFully(block, ty_src, final_elem_ty);
+
return;
}
try sema.requireRuntimeBlock(block, src);
- try sema.resolveTypeLayout(block, ty_src, final_elem_ty);
+ try sema.resolveTypeFully(block, ty_src, final_elem_ty);
// Change it to a normal alloc.
sema.air_instructions.set(ptr_inst, .{
test/behavior/bugs/11181.zig
@@ -0,0 +1,31 @@
+const builtin = @import("builtin");
+
+test "const inferred array of slices" {
+ if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+
+ const T = struct { v: bool };
+
+ const decls = [_][]const T{
+ &[_]T{
+ .{ .v = false },
+ },
+ };
+ _ = decls;
+}
+
+test "var inferred array of slices" {
+ if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+
+ const T = struct { v: bool };
+
+ var decls = [_][]const T{
+ &[_]T{
+ .{ .v = false },
+ },
+ };
+ _ = decls;
+}
test/behavior.zig
@@ -66,6 +66,7 @@ test {
_ = @import("behavior/bugs/11046.zig");
_ = @import("behavior/bugs/11139.zig");
_ = @import("behavior/bugs/11165.zig");
+ _ = @import("behavior/bugs/11181.zig");
_ = @import("behavior/call.zig");
_ = @import("behavior/cast.zig");
_ = @import("behavior/comptime_memory.zig");