diff --git a/src/Sema.zig b/src/Sema.zig index 20be9e705274..b4080b5280f1 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -20134,7 +20134,7 @@ fn structInitAnon( return sema.addConstantMaybeRef(struct_val, is_ref); }; - try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{ + try sema.requireRuntimeBlock(block, src, block.src(.{ .init_elem = .{ .init_node_offset = src.offset.node_offset.x, .elem_index = @intCast(runtime_index), } })); @@ -20282,7 +20282,7 @@ fn zirArrayInit( return sema.addConstantMaybeRef(result_val.toIntern(), is_ref); }; - try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{ + try sema.requireRuntimeBlock(block, src, block.src(.{ .init_elem = .{ .init_node_offset = src.offset.node_offset.x, .elem_index = runtime_index, } })); 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 000000000000..37455d5a04dc --- /dev/null +++ b/test/cases/compile_errors/runtime_value_in_comptime_array.zig @@ -0,0 +1,16 @@ +fn comptimeArray(comptime _: []const u8) void {} +fn bar() u8 { + return 123; +} + +pub fn main() void { + const y = bar(); + comptimeArray(&.{y}); +} + +// error +// +// :8:21: error: unable to evaluate comptime expression +// :8:22: note: operation is runtime due to this operand +// :8: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 000000000000..70f8edba81f0 --- /dev/null +++ b/test/cases/compile_errors/runtime_value_in_comptime_struct.zig @@ -0,0 +1,16 @@ +fn comptimeStruct(comptime _: anytype) void {} +fn bar() u8 { + return 123; +} + +pub fn main() void { + const y = bar(); + comptimeStruct(.{ .foo = y }); +} + +// error +// +// :8:21: error: unable to evaluate comptime expression +// :8:24: note: operation is runtime due to this operand +// :8:21: note: argument to comptime parameter must be comptime-known +// :1:19: note: parameter declared comptime here