From 264bd7053edb948d0f96525b54b859c0422e12a2 Mon Sep 17 00:00:00 2001 From: Jackson Wambolt Date: Sat, 28 Jun 2025 19:33:38 -0500 Subject: [PATCH] Sema: remove incorrect `requireRuntimeBlock` calls Part of #22353 Resolves: #24273 Co-Authored-By: Matthew Lugg --- src/Sema.zig | 14 ++------------ .../runtime_value_in_comptime_array.zig | 14 ++++++++++++++ .../runtime_value_in_comptime_struct.zig | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 test/cases/compile_errors/runtime_value_in_comptime_array.zig create mode 100644 test/cases/compile_errors/runtime_value_in_comptime_struct.zig diff --git a/src/Sema.zig b/src/Sema.zig index f81bb15f87..d7add0724d 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -19572,7 +19572,7 @@ fn structInitAnon( try sema.declareDependency(.{ .interned = struct_ty }); try sema.addTypeReferenceEntry(src, struct_ty); - const runtime_index = opt_runtime_index orelse { + _ = opt_runtime_index orelse { const struct_val = try pt.intern(.{ .aggregate = .{ .ty = struct_ty, .storage = .{ .elems = values }, @@ -19580,11 +19580,6 @@ fn structInitAnon( return sema.addConstantMaybeRef(struct_val, is_ref); }; - try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{ - .init_node_offset = src.offset.node_offset.x, - .elem_index = @intCast(runtime_index), - } })); - if (is_ref) { const target = zcu.getTarget(); const alloc_ty = try pt.ptrTypeSema(.{ @@ -19713,7 +19708,7 @@ fn zirArrayInit( if (!comptime_known) break @intCast(i); } else null; - const runtime_index = opt_runtime_index orelse { + _ = opt_runtime_index orelse { const elem_vals = try sema.arena.alloc(InternPool.Index, resolved_args.len); for (elem_vals, resolved_args) |*val, arg| { // We checked that all args are comptime above. @@ -19728,11 +19723,6 @@ fn zirArrayInit( return sema.addConstantMaybeRef(result_val.toIntern(), is_ref); }; - try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{ - .init_node_offset = src.offset.node_offset.x, - .elem_index = runtime_index, - } })); - if (is_ref) { const target = zcu.getTarget(); const alloc_ty = try pt.ptrTypeSema(.{ diff --git a/test/cases/compile_errors/runtime_value_in_comptime_array.zig b/test/cases/compile_errors/runtime_value_in_comptime_array.zig new file mode 100644 index 0000000000..804cd258fb --- /dev/null +++ b/test/cases/compile_errors/runtime_value_in_comptime_array.zig @@ -0,0 +1,14 @@ +fn comptimeArray(comptime _: []const u8) void {} +fn bar() u8 { + return 123; +} +export fn entry() void { + const y = bar(); + comptimeArray(&.{y}); +} + +// error +// +// :7:19: error: unable to resolve comptime value +// :7:19: note: argument to comptime parameter must be comptime-known +// :1:18: note: parameter declared comptime here diff --git a/test/cases/compile_errors/runtime_value_in_comptime_struct.zig b/test/cases/compile_errors/runtime_value_in_comptime_struct.zig new file mode 100644 index 0000000000..acaef3c543 --- /dev/null +++ b/test/cases/compile_errors/runtime_value_in_comptime_struct.zig @@ -0,0 +1,14 @@ +fn comptimeStruct(comptime _: anytype) void {} +fn bar() u8 { + return 123; +} +export fn entry() void { + const y = bar(); + comptimeStruct(.{ .foo = y }); +} + +// error +// +// :7:21: error: unable to resolve comptime value +// :7:21: note: argument to comptime parameter must be comptime-known +// :1:19: note: parameter declared comptime here