Commit 264bd7053e

Jackson Wambolt <jtwambolt@gmail.com>
2025-06-29 02:33:38
Sema: remove incorrect `requireRuntimeBlock` calls
Part of #22353 Resolves: #24273 Co-Authored-By: Matthew Lugg <mlugg@mlugg.co.uk>
1 parent ac1e73e
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(.{
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
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