aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-08-26 16:55:32 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2023-08-28 17:25:39 -0400
commitacd35a1aa75c78dc24859fa658f6d3e25e330b8a (patch)
tree974281bb9fcca0dd474138bf14f71508e8107f00 /src/Module.zig
parentbdbe16c47a1a7bb7412bcfbf39c9f32d22a7e2cb (diff)
downloadzig-acd35a1aa75c78dc24859fa658f6d3e25e330b8a.tar.gz
zig-acd35a1aa75c78dc24859fa658f6d3e25e330b8a.zip
Sema: factor out `NeededComptimeReason` from comptime value resolution
This makes the call sites easier to read, reduces the number of `catch` expressions required, and prepares for comptime reasons to appear earlier in the list of notes.
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/Module.zig b/src/Module.zig
index c13be489bb..d1b1e9b357 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -4147,7 +4147,9 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
const address_space_src: LazySrcLoc = .{ .node_offset_var_decl_addrspace = 0 };
const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };
const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };
- const decl_tv = try sema.resolveInstValue(&block_scope, init_src, result_ref, "global variable initializer must be comptime-known");
+ const decl_tv = try sema.resolveInstValue(&block_scope, init_src, result_ref, .{
+ .needed_comptime_reason = "global variable initializer must be comptime-known",
+ });
// Note this resolves the type of the Decl, not the value; if this Decl
// is a struct, for example, this resolves `type` (which needs no resolution),
@@ -4257,7 +4259,9 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
decl.@"linksection" = blk: {
const linksection_ref = decl.zirLinksectionRef(mod);
if (linksection_ref == .none) break :blk .none;
- const bytes = try sema.resolveConstString(&block_scope, section_src, linksection_ref, "linksection must be comptime-known");
+ const bytes = try sema.resolveConstString(&block_scope, section_src, linksection_ref, .{
+ .needed_comptime_reason = "linksection must be comptime-known",
+ });
if (mem.indexOfScalar(u8, bytes, 0) != null) {
return sema.fail(&block_scope, section_src, "linksection cannot contain null bytes", .{});
} else if (bytes.len == 0) {