commit 264bd7053edb948d0f96525b54b859c0422e12a2 (tree)
parent ac1e73e249f8ce06bc7c89d2bdc4359b0399236c
Author: Jackson Wambolt <jtwambolt@gmail.com>
Date: Sat, 28 Jun 2025 19:33:38 -0500
Sema: remove incorrect `requireRuntimeBlock` calls
Part of #22353
Resolves: #24273
Co-Authored-By: Matthew Lugg <mlugg@mlugg.co.uk>
Diffstat:
3 files changed, 30 insertions(+), 12 deletions(-)
diff --git 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
@@ -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
@@ -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