authorgravatar for jtwambolt@gmail.comJackson Wambolt <jtwambolt@gmail.com> 2025-06-28 19:33:38-05:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-07-31 22:28:46+01:00
log264bd7053edb948d0f96525b54b859c0422e12a2
tree35ea671688ad92693f4579c6de89f9a1f6e3b98e
parentac1e73e249f8ce06bc7c89d2bdc4359b0399236c

Sema: remove incorrect `requireRuntimeBlock` calls

Part of #22353 Resolves: #24273 Co-Authored-By: Matthew Lugg <mlugg@mlugg.co.uk>

3 files changed, 30 insertions(+), 12 deletions(-)

src/Sema.zig+2-12
......@@ -19572,7 +19572,7 @@ fn structInitAnon(
1957219572 try sema.declareDependency(.{ .interned = struct_ty });
1957319573 try sema.addTypeReferenceEntry(src, struct_ty);
1957419574
19575 const runtime_index = opt_runtime_index orelse {
19575 _ = opt_runtime_index orelse {
1957619576 const struct_val = try pt.intern(.{ .aggregate = .{
1957719577 .ty = struct_ty,
1957819578 .storage = .{ .elems = values },
......@@ -19580,11 +19580,6 @@ fn structInitAnon(
1958019580 return sema.addConstantMaybeRef(struct_val, is_ref);
1958119581 };
1958219582
19583 try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{
19584 .init_node_offset = src.offset.node_offset.x,
19585 .elem_index = @intCast(runtime_index),
19586 } }));
19587
1958819583 if (is_ref) {
1958919584 const target = zcu.getTarget();
1959019585 const alloc_ty = try pt.ptrTypeSema(.{
......@@ -19713,7 +19708,7 @@ fn zirArrayInit(
1971319708 if (!comptime_known) break @intCast(i);
1971419709 } else null;
1971519710
19716 const runtime_index = opt_runtime_index orelse {
19711 _ = opt_runtime_index orelse {
1971719712 const elem_vals = try sema.arena.alloc(InternPool.Index, resolved_args.len);
1971819713 for (elem_vals, resolved_args) |*val, arg| {
1971919714 // We checked that all args are comptime above.
......@@ -19728,11 +19723,6 @@ fn zirArrayInit(
1972819723 return sema.addConstantMaybeRef(result_val.toIntern(), is_ref);
1972919724 };
1973019725
19731 try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{
19732 .init_node_offset = src.offset.node_offset.x,
19733 .elem_index = runtime_index,
19734 } }));
19735
1973619726 if (is_ref) {
1973719727 const target = zcu.getTarget();
1973819728 const alloc_ty = try pt.ptrTypeSema(.{
test/cases/compile_errors/runtime_value_in_comptime_array.zig created+14
......@@ -0,0 +1,14 @@
1fn comptimeArray(comptime _: []const u8) void {}
2fn bar() u8 {
3 return 123;
4}
5export fn entry() void {
6 const y = bar();
7 comptimeArray(&.{y});
8}
9
10// error
11//
12// :7:19: error: unable to resolve comptime value
13// :7:19: note: argument to comptime parameter must be comptime-known
14// :1:18: note: parameter declared comptime here
test/cases/compile_errors/runtime_value_in_comptime_struct.zig created+14
......@@ -0,0 +1,14 @@
1fn comptimeStruct(comptime _: anytype) void {}
2fn bar() u8 {
3 return 123;
4}
5export fn entry() void {
6 const y = bar();
7 comptimeStruct(.{ .foo = y });
8}
9
10// error
11//
12// :7:21: error: unable to resolve comptime value
13// :7:21: note: argument to comptime parameter must be comptime-known
14// :1:19: note: parameter declared comptime here