Skip to content

Sema: give src loc to requireRuntimeBlock #24295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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),
} }));
Expand Down Expand Up @@ -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,
} }));
Expand Down
16 changes: 16 additions & 0 deletions test/cases/compile_errors/runtime_value_in_comptime_array.zig
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions test/cases/compile_errors/runtime_value_in_comptime_struct.zig
Original file line number Diff line number Diff line change
@@ -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